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

Performance of splice #405

Open
amk221 opened this issue Jun 1, 2023 · 1 comment
Open

Performance of splice #405

amk221 opened this issue Jun 1, 2023 · 1 comment

Comments

@amk221
Copy link

amk221 commented Jun 1, 2023

Is there anything that can be done to improve the performance of .splice

this.data = tracked([/* 10000 items */]);
console.time('splice');
this.data.splice(0, 1);
console.timeEnd('splice');
// 10ms

vs.

this.data = [/* 10000 items */];
console.time('splice');
this.data.splice(0, 1);
console.timeEnd('splice');
// 0.002
@lifeart
Copy link
Contributor

lifeart commented Jan 26, 2024

I think we could have a test to catch this kind of regressions:

const array1 = new Array(100000).fill(null);
const t1 = performance.now();
array1.splice(0, 1);
const t2 = performance.now();
const controlWindow = t2-t1;

const array2 = tracked(new Array(100000).fill(null));
const t3 = performance.now();
array2.splice(0, 1);
const t4 = performance.now();
const experimentWindow = t4-t3;

const deviation = 1.2; // 20%
assert.ok(experimentWindow < controlWindow*deviation)

MichalBryxi added a commit to MichalBryxi/tracked-built-ins that referenced this issue Jan 26, 2024
- 100k items means that the performance test will take ~0.25s (1.7 GHz Quad-Core Intel Core i7) and seems be failing reliably.
- Added other assertions to make sure we're testing _real_ data and that we don't mutate the initial data set as we go.

Relates to: tracked-tools#405
MichalBryxi added a commit to MichalBryxi/tracked-built-ins that referenced this issue Jan 26, 2024
- 1M items means that the performance test will take 4.5s (1.7 GHz Quad-Core Intel Core i7).
- We need enough items to make sure there is no zero in the comparison equation. Right now it's: `4423.399999976158 < 2 * 1.2`
- Added other assertions to make sure we're testing _real_ data and that we don't mutate the initial data set as we go.

Relates to: tracked-tools#405
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants