Eliminate duplicate hash calculations for getSymbolInSymbolMaps
#1801
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.
Introduction
WPS Presentation can be run on RISC-V Lichee Pi 4A with the power of box64. And I did profiling for it, in order to find the performance bottleneck. The profiling result is shown below:
So I investigated why
getSymbolInSymbolMaps
(kh_get_symbolmap
&kh_get_symbol2map
) costs so much. I found thatgetSymbolInSymbolMaps
callskh_get
6 times at the worst case, and the most expensive calculation inkh_get
is "hashing". Symbols are strings and current string hashing function needs to traversal the whole string.My idea is to eliminate the duplicate "hashing", since the pass-in symbol name does not change during
getSymbolInSymbolMaps
.Implementation
The optimization is straightforward. That is, just calculate the hash once and reuse the result. To achieve this, I added two APIs called
kh_hash
&kh_get_with_hash
, and applied them forgetSymbolInSymbolMaps
.Evaluation
I evaluated the start-up time of WPS Presentation. Results are shown here:
where the "logo" column means the time when the logo displays, and the "full" column means the time when the WPS Presentation fully starts up.
So this simple optimization does improve the performance a lot in my use case. And I am sending this PR and sharing the results with you.