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

Swap allocated_size and total_size to prevent cache misses on fast path. #13834

Closed
wants to merge 1 commit into from

Conversation

copybara-service[bot]
Copy link

Swap allocated_size and total_size to prevent cache misses on fast path.

Note: I don't know how to simulate cache miss reliably in a microbenchmark, so the change does not show any significant diff on the added BMs.

Motivation:

  1. It's more aligned with class design: total_size is the capacity of Rep, so it makes more sense to store it there.
  2. On the fast path, we check allocated_size, and with this change we do not to dereference Rep to read it (slow path is unchanged, as it needs both capacity and allocated size).
  3. fast path is inlined and as a result we reduce code bloat.

Also added removed redundant check with MaybeExtend in some methods: these methods already know that call to extend is necessary, so no need to go through Reserve route.

nit: deduped code by reusing AddAllocatedForParse in other Add functions.

Note: I don't know how to simulate cache miss reliably in a microbenchmark, so the change does not show any significant diff on the added BMs.

Motivation:
 1. It's more aligned with class design: total_size is the capacity of Rep, so it makes more sense to store it there.
 2. On the fast path, we check allocated_size, and with this change we do not to dereference Rep to read it (slow path is unchanged, as it needs both capacity and allocated size).
 3. fast path is inlined and as a result we reduce code bloat.

Also added removed redundant check with MaybeExtend in some methods: these methods already know that call to extend is necessary, so no need to go through `Reserve` route.

nit: deduped code by reusing AddAllocatedForParse in other Add functions.
PiperOrigin-RevId: 562501058
@github-actions
Copy link

Auto-closing Copybara pull request

@github-actions github-actions bot closed this Sep 11, 2023
@github-actions github-actions bot deleted the test_562501058 branch September 11, 2023 10:02
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.

1 participant