-
Notifications
You must be signed in to change notification settings - Fork 4.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
Cache item info for crafting GUI full-text search #77914
Cache item info for crafting GUI full-text search #77914
Conversation
277ba09
to
5e0c847
Compare
5e0c847
to
38955fc
Compare
Test failure unrelated:
https://github.com/CleverRaven/Cataclysm-DDA/actions/runs/11873797927/job/33089014493?pr=77914
Restarting tests. |
The cache survives the save-load cycle. Potential bugs: World bug Fulltext searching items in world A will cache the results. Load world B. It will use this cache. It is unlikely that anyone will ever encounter this bug. Avatar bug Switch conciseness from avatar A to another character B (I assume this does not take a turn, if it does, the cache is correctly invalidated). Also, I assume this can be done by choosing a new leader. Debug menu-only bugs solved by waiting a turn are not worth fixing. Use cached info with avatar B. |
Summary
Performance "Cache item info for crafting GUI full-text search"
Purpose of change
Cache results of "d:some item description"
. But it is done differently and better.Getting info on an item
item.info( true )
made more than 95% of the searching time (1m11s on my PC). When cached (rerun), the search takes about 400 ms! Making it over 100x faster.Speeds up on multiple levels:
Describe the solution
a variable local tosrc/uistate.h
. Should the code live somewhere else?src/recipe_dictionary.cpp
.Describe alternatives you've considered
Making the regular function cache automatically. It would cause more changes to test.
The item info probably breaks (is not up to date) when you do something in less than a turn. I considered fixing that, but first I would need to find an example. Maybe it will matter more if it is used someplace else, like crafting GUI in general. And if it gets used.
Testing
Before
d:close
takes 1min8sec.After
d:close
takes 56sec now. The cache is utilized even for the first full-text search apparently. It has 845 hits and 3318 misses with a clear cache. The second time, it has all hits and no misses.d:close to skin,d:HEAD
. Took 55 seconds. Nice bonus: the percentage progress now concludes at 100% and finishes, before, it made the second 0 to 100% search for the second full-text search.Am I respecting item variants? Or something? Does it break for something?
Additional context
This could be used more. Like connected to the crafting GUI. I wanted to start with a super simple and useful implementation. We can do the rest in subsequent PRs.
The text might need to be wrapped for other use cases. In searching there is no wrapping.