Changing PromiseExecutor to use a Rust VecDeque #165
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The behavior should be identical, but this dramatically improves the performance. In my animation test demo it went from ~10 FPS to ~60 FPS!
There are two reasons for this:
It maintains a
VecDeque
in Rust, rather than using the browser's event loop queue. This means much less interop between Rust -> JS -> Rust, which means less overhead.It avoids creating garbage as much as possible.
The old implementation created 3 functions and 2 Promises per event tick per Task. So if there were 100 Tasks that means it created 300 functions + 200 Promises on every event tick.
The new implementation creates 1 Promise per event tick. So if there are 100 Tasks that means it creates 1 Promise on every event tick.
That means multiple orders of magnitude less garbage.
It seems that avoiding garbage is much more important for performance than using
VecDeque
, but either way it's a huge performance benefit.After these changes, the biggest performance bottlenecks seem to be from the
to_js
andto_js_string
functions.