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

Optimize tic api call performance in LUA. #1628

Merged
merged 1 commit into from
Nov 1, 2021

Conversation

vsariola
Copy link
Contributor

@vsariola vsariola commented Oct 9, 2021

Previously, the tic_core* was associated with a global variable named "_TIC80". Finding the global variable with that name took surprising amount of time, according to profiling. With this optimization, each API function is associated with tic_core* through lua_pushcclosure mechanism. Closures are functions that are associated with certain "upvalues". Fetching an upvalue is very fast in LUA.

Previously, the tic_core* was associated with a global variable named "_TIC80" and every api call fetches the tic_core by finding the global with this name. Finding the global variable with that name took surprising amount of time, according to profiling. With this optimization, each API function is associated with tic_core* through lua_pushcclosure mechanism. Closures are functions that are associated with certain "upvalues". Fetching an upvalue is very fast in LUA.

checkForceExit still fetches the tic_core from the global, as the hook is an ordinary function, not a global.
Copy link
Owner

@nesbox nesbox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it works faster now.
Thank you for the help.

@nesbox nesbox merged commit 9a716af into nesbox:master Nov 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants