-
Notifications
You must be signed in to change notification settings - Fork 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
Content ID caching in Lua #12444
Content ID caching in Lua #12444
Conversation
Closing since equivalent functionality is being implemented in #12438. |
I'll reopen this as it seems the other PR isn't very active anyway. |
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.
👍 For concept.
Code looks fine.
Haven't tested.
You could do a small benchmark to verify that it's faster.
|
||
local content2name = setmetatable({}, { | ||
__index = function(self, id) | ||
return old_get_name_from_content_id(id) |
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.
Same as above.
Should I add a setting to disable this, in case people want to save memory? At the most, it could use on the order of one megabyte per thread. Might that be significant on Raspberry Pi servers? |
No. There are much more impactful things that could be tweaked to save RAM. |
This needs to be benchmarked to ensure the performance increase is worth the added code |
I added benchmark commands. Here are the results on my computer:
|
What's the benefit of an additional content ID cache? When used heavily, such as in Lua mapgens, the content IDs are already cached by the mod where needed to speed up generation time. This does get rid of the function call entirely inside the 3D (or more) loop to iterate through the I very much believe in the "keep it simple, stupid" principle and I don't think this PR fits into that scheme. No optimization helps if mods are programmed inefficiently. |
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.
(code review only this time)
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.
before:
Time: 7.07 ms
Time: 18.43 ms
after:
Time: 1.11 ms
Time: 2.55 ms
This is to let minetest#12609 work on the client.
0be3c26
to
ebf4401
Compare
I suggested this in #12438, where you can find some context/rationale. An alternative to this PR is to incorporate its changes into #12438.
To do
This PR is Ready for Review.
How to test
There's a unit test. You can also try the change with other mods that access raw content IDs.