Skip to content

Use locked segment by reference without cloning Arc#7176

Merged
timvisee merged 3 commits intodevfrom
locked-segment-get-ref
Aug 29, 2025
Merged

Use locked segment by reference without cloning Arc#7176
timvisee merged 3 commits intodevfrom
locked-segment-get-ref

Conversation

@timvisee
Copy link
Member

@timvisee timvisee commented Aug 29, 2025

Prefer to use a locked segment by reference, without cloning an Arc.

We use this function in at least 189 different places (including tests). This way we prevent unnecessarily bumping an atomic counter twice with each interaction.

I don't expect to see a noticeable difference in end to end benchmarks, but doing less work at runtime is always good. This function may be considered hot, and we've seen performance problems on very large CPUs when bumping a lot of atomics.

All Submissions:

  • Contributions should target the dev branch. Did you create your branch from dev?
  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New Feature Submissions:

  1. Does your submission pass tests?
  2. Have you formatted your code locally using cargo +nightly fmt --all command prior to submission?
  3. Have you checked your code using cargo clippy --all --all-features command?

@timvisee timvisee requested review from agourlay, generall and xzfc August 29, 2025 10:57
@timvisee timvisee marked this pull request as ready for review August 29, 2025 10:57
let segment = match proxy_segment {
LockedSegment::Proxy(proxy_segment) => {
proxy_segment.read().wrapped_segment.clone().get()
proxy_segment.read().wrapped_segment.get_cloned()
Copy link
Member Author

Choose a reason for hiding this comment

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

Effectively the only place (outside tests) where we actually need the owned Arc by cloning it.

@qdrant qdrant deleted a comment from coderabbitai bot Aug 29, 2025
@timvisee timvisee merged commit bb51da7 into dev Aug 29, 2025
16 checks passed
@timvisee timvisee deleted the locked-segment-get-ref branch August 29, 2025 11:26
timvisee added a commit that referenced this pull request Sep 29, 2025
* Use locked segment by reference without cloning Arc

* Remove unnecessary clone

* Return list of lock references
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.

4 participants