Skip to content

Commit 130794b

Browse files
authoredSep 22, 2022
perf: avoiding use of Object.defineProperty in Chunk constructor (#219)
1 parent 04a05bd commit 130794b

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed
 

‎benchmark/index.mjs

+7
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ async function bench() {
7575
}, s => {
7676
s.replace(/replacement/g, 'replacement\nReplacement');
7777
});
78+
79+
const size = 1000000;
80+
runWithInstance('overwrite', ['a'.repeat(size)], s => {
81+
for (let i = 1; i < size; i+=2) {
82+
s.overwrite(i, i+1, 'b');
83+
}
84+
});
7885
}
7986

8087
bench();

‎src/Chunk.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@ export default class Chunk {
1111
this.storeName = false;
1212
this.edited = false;
1313

14-
// we make these non-enumerable, for sanity while debugging
15-
Object.defineProperties(this, {
16-
previous: { writable: true, value: null },
17-
next: { writable: true, value: null },
18-
});
14+
if (DEBUG) {
15+
// we make these non-enumerable, for sanity while debugging
16+
Object.defineProperties(this, {
17+
previous: { writable: true, value: null },
18+
next: { writable: true, value: null },
19+
});
20+
} else {
21+
this.previous = null;
22+
this.next = null;
23+
}
1924
}
2025

2126
appendLeft(content) {

0 commit comments

Comments
 (0)
Please sign in to comment.