-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Enable Jit for Generators, Asyncs and Async Generators #6662
Conversation
- For in loops use an enumerator object - for optimisation reasons this is cached in a known location - in nested for-in loops containing yield cache could fail to restore - remove a step from the process and bring load nearer to usage
- BailOnNoProfile marks all code after it as dead - if variable is used in a yield BUT incremented after BailOnNoProfile - Jit would delete the increment and mark variable as constant - interpreter would increment BUT JIT would reload as const - would yield same value multiple times Ideally should introduce Generator/Async specific version of BailOnNoProfile That doesn't mark code after it as dead - but that would be larger work. For now disable BailOnNoProfile for generators/Asyncs.
- Extra yield inserted at the top of Generator functions - so Params with side effects can be executed upon function call - then stop at the yield untill .next() is used - in cases where there are no params with side effets his is not needed - use a condition to only do it when needed - saves several extra ops - Had to update TTD code for this (it expected all Gens to have state) - AsyncGenerator parameters needed copying to heap on call previously this was done when executing until the startup yield
- exclude ARM which has not been tested - excludes code running with debugger attached (not tested) - excludes functions containing try/catch (not tested) - excludes Module globals (unlikely to benefit) - add tests for bugs fixed above
@ppenzin sorry I know this isn't our top priority but I've been wanting to get it in for so long.... Please could you take a look when you have time. |
I am glad you got it fixed, agree we should check this while it is still fresh. Do you want this shipping as part of the upcoming release? If not, we can cut the release branch right before merging it in. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
This PR enables the JIT in both FullJit and SimpleJit mode for Generator Functions, Async Functions and Async Generator Functions (Collectively referred to internally as Coroutines)
Exceptions
Work Done in this PR
Fix register mismatch in Jit
yield*
statements within Async GeneratorsFix handling of For-In
yields
was not working correctlyDisable BailOnNoProfile in Coroutines
++i
is marked as dead++i
is dead, i is marked as a single definition int - a constantyield 0
-> BailOnNoProfile -> yield 1 (in the interpreter) -> try jitted code again - Bails out with i = 0 as it is a const -> yield 1 (in the interpreter)Remove unnecessary startup yield
Enable
Future Work
A. Look at enabling for functions containing try/catch - needs to be explored don't know what issues may arise
B. Create an alternative form of BailOnNoProfile that can be used in Coroutines
C. Look at Jitting loop bodies that don't contain yield - (including loop bodies in Modules)
Fix #5877