-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Avoid using shift in flush #4356
Conversation
We noticed that there was a large amount of memory being created as part of the flush method, which seems to be due to some array optimizations in old JS engines. This seems to be easily fixed by changing to a simple for loop instead of a while loop that modifies the array during iteration. This is the same pattern that is used for the `render_callbacks`.
This is great, shift is extremely expensive even in modern engines. cc trentm/node-bunyan#279 But, I will have to say @kesne , this |
The test failure looks like a legitimate one. This apparently causes an infinite loop with custom elements. |
@Conduitry It appears that the failed tests are due to the internal It seems like the easiest resolution is to only allow one copy of the |
Just wondering, would it be better to do the same thing ( replace while with a for ) for : while (binding_callbacks.length) binding_callbacks.pop()(); Not sure how JS engine handle memory allocation for array, but in any case, seems better to have a for loop in there, and reset the size at the end like you did for this optims ? Also, is dirty_components can change while executing the for loop ? If it is constant, than, if I remember correctly, using |
@olivierchatry I'm unsure about the while case, it doesn't seem like there's any cases where it's causing problematic amounts of memory. As for |
Ho, sorry, I was not clear, I was not talking about memory directly, but more about CPU usage, I'm wondering if it is faster to do a for then a clear, than a while with a pop. Thanks for the heads up, I think you are very correct, it's minor optimization anyway, and I'm not even sure it would change anything. |
Actually, seems pop is faster than length = 0, wild guess, pop does not deallocate memory, just the internal "index", while length = 0 actually deallocate ( but would have to check the code ). Anyway sorry for the thread, I'm reading the inside of svelt to learn it, and this PR seemed cool. Thanks a lot ! |
I merged this PR earlier today - Are there other changes that people think should happen before the next release? I don't have strong opinions or much familiarity with the performance differences between the various ways of doing this. |
I don’t think so. This should be fine to release as-is. This solves a specific de-opt case whereas the discussion here is more around further ways to optimize. |
3.18.2 has been released with this change, thanks! |
Ha yes, I did not want to hijack the PR at all, very sorry. Was just
curious about some performance related questions while reading svelte code
/ PR. Thanks a lot for the great work !
…On Sun, Feb 9, 2020, 3:38 PM Conduitry ***@***.***> wrote:
3.18.2 has been released with this change, thanks!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4356?email_source=notifications&email_token=AAJVOG6FRUNBXIWV2OME2ZLRCAIPRA5CNFSM4KPMRSYKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELGODRA#issuecomment-583852484>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJVOG2X5HPW764W73HO2HDRCAIPRANCNFSM4KPMRSYA>
.
|
We noticed that there was a large amount of memory being created as part of the flush method, which seems to be due to some array optimizations in old JS engines. This seems to be easily fixed by changing to a simple for loop instead of a while loop that modifies the array during iteration. This is the same pattern that is used for the
render_callbacks
.Before submitting the PR, please make sure you do the following
npm run lint
!)Tests
npm test
oryarn test
)