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

Eliminate duplicate hash calculations for getSymbolInSymbolMaps #1801

Merged
merged 1 commit into from
Sep 6, 2024

Conversation

Coekjan
Copy link
Contributor

@Coekjan Coekjan commented Sep 6, 2024

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:

image

So I investigated why getSymbolInSymbolMaps (kh_get_symbolmap & kh_get_symbol2map) costs so much. I found that getSymbolInSymbolMaps calls kh_get 6 times at the worst case, and the most expensive calculation in kh_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 for getSymbolInSymbolMaps.

Evaluation

I evaluated the start-up time of WPS Presentation. Results are shown here:

image

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.

@ptitSeb
Copy link
Owner

ptitSeb commented Sep 6, 2024

Interesting analysis. Thanks for the break down and the optimisation. That's a good one.

That looks like a good loading time speedup.

@ptitSeb ptitSeb merged commit 7dc59ac into ptitSeb:main Sep 6, 2024
23 checks passed
@Coekjan Coekjan deleted the hash-once branch September 6, 2024 12:57
JunChi1022 pushed a commit to JunChi1022/box64 that referenced this pull request Sep 12, 2024
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