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

NBN_Connection layout is cache unfriendly #21

Closed
Phireh opened this issue Jan 7, 2022 · 2 comments
Closed

NBN_Connection layout is cache unfriendly #21

Phireh opened this issue Jan 7, 2022 · 2 comments

Comments

@Phireh
Copy link

Phireh commented Jan 7, 2022

__NBN_Connection is big enough (a little above 1 MB per connection) that it doesn't fit into the L2 cache of many systems.

A quick look into a frequently called function like Connection_ReadNextMessageFromStream shows that channels and endpoint are accessed often and immediately after each other, however, their positions in the struct are very far apart. On my Linux 64b system they look like this:

(gdb) p offsetof(NBN_Connection, channels)
$1 = (NBN_Channel *(*)[32]) 0x107318
(gdb) p offsetof(NBN_Connection, endpoint)
$2 = (struct __NBN_Endpoint **) 0x30

More than a MB apart. I believe this is introducing cache misses and impacting performance. The fix is very straightforward: move frequently used members of the struct closer together.

@nathhB
Copy link
Owner

nathhB commented Jan 25, 2022

@Phireh hey, do you want to do this one?

@nathhB
Copy link
Owner

nathhB commented Aug 6, 2022

Merged this PR: #26

@nathhB nathhB closed this as completed Aug 6, 2022
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

No branches or pull requests

2 participants