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

refactor: don't store torrent hashes in QStrings #1428

Merged
merged 3 commits into from Sep 7, 2020

Conversation

ckerr
Copy link
Member

@ckerr ckerr commented Sep 7, 2020

Minor optimization to the Qt client's Torrent class: keep the hash in a std::array<uint8_t, 20> instead of in a QString. Since the size of the array is known at compile time, it can be built into the Torrent class and the extra heap allocs for QString's internals can be avoided.

This saves about 5 MB from the RES size on my 15K torrent testbed, which is better than I expected, considering that the raw hashString char array size was 41 bytes so the raw data savings is only (15K torrents * (41 bytes - 20 bytes)) = 0.31 MB.

5 MB out of 15K torrents isn't a huge win; however, since we don't display the hashString anywhere except for in the details dialog, building the string on demand is not expensive.

This lets replace the hashString QString allocation with a compile-time
array that's included in sizeof the Torrent struct that owns it.
@ckerr ckerr added the scope:qt label Sep 7, 2020
@ckerr
Copy link
Member Author

ckerr commented Sep 7, 2020

appveyor CI failure is unrelated -- it's a regression in MSVC and I've got a workaround for it in a separate PR

@ckerr ckerr merged commit 9f7c865 into master Sep 7, 2020
@ckerr ckerr deleted the dont-keep-hashStrings-in-memory branch September 7, 2020 21:19
@ckerr ckerr added the type:perf A code change that improves performance label Oct 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope:qt type:perf A code change that improves performance
Development

Successfully merging this pull request may close these issues.

None yet

1 participant