Skip to content

[DYNAREC] Optimized bigblock add_next performance with hash table#3890

Merged
ptitSeb merged 2 commits into
ptitSeb:mainfrom
ksco:optim-add-next
May 24, 2026
Merged

[DYNAREC] Optimized bigblock add_next performance with hash table#3890
ptitSeb merged 2 commits into
ptitSeb:mainfrom
ksco:optim-add-next

Conversation

@ksco
Copy link
Copy Markdown
Collaborator

@ksco ksco commented May 24, 2026

I noticed that when I run wine explorer with Wine 11.8 without DynaCache on a Snapdragon 8cx Gen3, there is a hotspot on add_next:

-   22.63%    22.62%  explorer.exe     box64  [.] add_next
     0.01%     0.01%  wine64           box64  [.] add_next
     0.00%     0.00%  wineserver       box64  [.] add_next

After applying this optimization, the hotspot disappeared:

+    0.94%     0.57%  explorer.exe     box64  [.] add_next
     0.02%     0.01%  wine64           box64  [.] add_next
     0.00%     0.00%  conhost.exe      box64  [.] add_next

The measured startup time of wine explorer dropped from 21s to 16s, which is now quite close to the 14s achieved with DynaCache enabled.

I noticed that when I run `wine explorer` with Wine 11.8 without DynaCache on a Snapdragon 8cx Gen3, there is a hotspot on `add_next`:

```diff
-   22.63%    22.62%  explorer.exe     box64  [.] add_next
     0.01%     0.01%  wine64           box64  [.] add_next
     0.00%     0.00%  wineserver       box64  [.] add_next
```

After applying this optimization, the hotspot disappeared:

```diff
+    0.94%     0.57%  explorer.exe     box64  [.] add_next
     0.02%     0.01%  wine64           box64  [.] add_next
     0.00%     0.00%  conhost.exe      box64  [.] add_next
```

The measured startup time of `wine explorer` dropped from 21s to 16s, which is now quite close to the 14s achieved with DynaCache enabled.
if(k != kh_end(khnextset))
return;
int ret;
kh_put(nextset, khnextset, addr, &ret);
Copy link
Copy Markdown
Owner

@ptitSeb ptitSeb May 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a way to just use kh_put here, instead of kh_get+kh_put, and check ret to see if kh_put actualy add a key or not (ret==0 eans key aready exist so can exit here)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@ptitSeb
Copy link
Copy Markdown
Owner

ptitSeb commented May 24, 2026

Interesting, but I wonder if an rbtree woud be better, as there is a notion of order in the added addresses?

@ksco
Copy link
Copy Markdown
Collaborator Author

ksco commented May 24, 2026

I'll give rbtree a try.

@ksco
Copy link
Copy Markdown
Collaborator Author

ksco commented May 24, 2026

nah I don't think an rbtree is useful here, a sorted array is more suitable. but anyway, get_closest_next() was not the hotspot here, so that doesn't matter.

@ptitSeb ptitSeb merged commit 8707b8d into ptitSeb:main May 24, 2026
28 checks passed
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