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

Switch optimisation #860

Closed
XmiliaH opened this issue May 9, 2024 · 1 comment
Closed

Switch optimisation #860

XmiliaH opened this issue May 9, 2024 · 1 comment
Labels
question Further information is requested

Comments

@XmiliaH
Copy link
Contributor

XmiliaH commented May 9, 2024

I would like to add an optimisation to the switch statement that makes the test for the constant cases O(log n) instead of the current O(n).

This would include adding a new upvalue (switch-caches) (name up for debate but should be not accessible from the script) to the chunk.
When a switch is executed for the first time a lookup table is generated and cached under some key in this upvalue table. This lookup table maps values to case-ids and allows to generate a binary search to jump to the cases. In case no constant case matched all the dynamic cases are tested.

Would this be something that is of interest?

@Sainan Sainan added the question Further information is requested label May 9, 2024
@Sainan
Copy link
Collaborator

Sainan commented May 9, 2024

Absolutely. I think my comments in #858 explain pretty well that I am very much in favour of switch blocks being optimised as long as it's Lua bytecode compatible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants