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

replace hardcoded hookInterval with BogoMIPS calculator #2877

Merged
merged 1 commit into from Jul 4, 2018

Conversation

asiekierka
Copy link
Contributor

@asiekierka asiekierka commented Jul 4, 2018

During my development on Kallisti, I decided to look into OpenComputers's performance characteristics relative to native Lua 5.3.

During my research, I found out that the default hookInterval (100 Lua VM instructions) is far too low, as the cost of the deadline detection hook seems to be in the tens of Lua VM instructions by itself (plus a JNI escape in computer.realTime()!). I found that setting it to, say, 10000, improves performance in Lua scripts by about 60-70% (which is pretty good - faster performance means less deadline hitting, after all).

However, on very fast computers 10000 might still be too low and on very slow computers 10000 might be too high. For this reason, I wrote a simple "BogoMIPS"-esque calculator that tries to calculate a (very rough - for one, it still eats up time in the hook itself) count of executed instructions in a second, then sets the hookInterval to 0.005 times that (so a rough count of executed instructions in roughly 5 milliseconds, as that is still much better than the necessary precision).

tl;dr Boosts Lua script performance by 60-70%, looks pretty good. Should probably be forwarded to all repositories.

(If you're curious, the act of setting a debug.sethook() on VM instructions alone adds 50% of overhead. But I don't think we can quite get rid of that, for obvious reasons - Lua does not make any threading guarantees.)

@payonel payonel merged commit daff228 into MightyPirates:master-MC1.7.10 Jul 4, 2018
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.

None yet

2 participants