Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: avoiding use of Object.defineProperty in Chunk constructor #219

Merged
merged 2 commits into from Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions benchmark/index.mjs
Expand Up @@ -75,6 +75,13 @@ async function bench() {
}, s => {
s.replace(/replacement/g, 'replacement\nReplacement');
});

const size = 1000000;
runWithInstance('overwrite', ['a'.repeat(size)], s => {
for (let i = 1; i < size; i+=2) {
s.overwrite(i, i+1, 'b');
}
});
}

bench();
15 changes: 10 additions & 5 deletions src/Chunk.js
Expand Up @@ -11,11 +11,16 @@ export default class Chunk {
this.storeName = false;
this.edited = false;

// we make these non-enumerable, for sanity while debugging
Object.defineProperties(this, {
previous: { writable: true, value: null },
next: { writable: true, value: null },
});
if (DEBUG) {
// we make these non-enumerable, for sanity while debugging
Object.defineProperties(this, {
previous: { writable: true, value: null },
next: { writable: true, value: null },
});
} else {
this.previous = null;
this.next = null;
}
}

appendLeft(content) {
Expand Down