-
Notifications
You must be signed in to change notification settings - Fork 689
Auto growing stack and registry #236
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gets rid of some cache misses when reading and manipulating stack pos
should not auto grow by default (for backwards compat) when auto grow is enabled, should in fact auto grow
most of the time it is a cheap if statement
Owner
|
Thanks for your great contribution! I'll check your PR this weekend. |
Owner
|
@tul LGTM! Could you update the README? |
Contributor
Author
|
Yes, will do. |
Contributor
Author
|
@yuin I've updated the README, please let me know if you would like anything clarifying or any further changes. |
Owner
|
@tul LGTM, I've merged your PR. I appreciate your work! |
Contributor
Author
|
Thanks - and thanks for all your work on gopher lua! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #197 .
Changes proposed in this pull request:
LState's callstack to grow / shrink automatically (up to a max size)LState's registry to grow automatically (up to a max size)It's been a long time since I opened #197 , sorry for the delay. Please feel free to feedback on this PR or ask for changes.
There are two parts to this PR - first the registry can be set to auto grow as needed. Originally, the registry was implemented as a fixed size slice. This PR simply allows this slice to be reallocated if it runs out of space. A maximum upper size to be set in the
Optionsstruct, as well as a grow step size. By default theRegistryMaxSizewill be0, which disables the auto grow behaviour and makes the code behaviour exactly the same as previously. As there is no penalty in this case, other than an inlined if statement, I have not abstracted the registry growth functionality via an interface.The second part of this PR is the more complicated, it allows the callstack to be automatically resized as needed. This has been implemented now via an interface with the
LStatebeing configured on construction to either use the previous fixed size callstack, or the new auto growing callstack from this PR. TheOptionsstruct dictates which one should be used.Abstracting the callstack into an interface is good in that it allows us to switch between implementations depending on the requirements : the auto growing one will use minimal memory, but has a slight performance penalty, whereas the fixed one will always use "worst case" memory, but will have predicable and fast performance.
Abstracting the callstack to be behind an interface has meant disabling the inlining which was in place for manipulating the stack from within the
LState. I have added benchmarks which just do stack manipulation and I did not think the performance hit was so bad, but it might be worth benchmaking the new code (in both the fixed and auto growing configurations) against some actual lua benchmarking scripts, to see how it fares in actual usage.