Skip to content

perf(allocator/vec2): reorder RawVec fields#11050

Merged
graphite-app[bot] merged 1 commit intomainfrom
05-15-refactor_allocator_vec2_reorder_rawvec_fields
May 15, 2025
Merged

perf(allocator/vec2): reorder RawVec fields#11050
graphite-app[bot] merged 1 commit intomainfrom
05-15-refactor_allocator_vec2_reorder_rawvec_fields

Conversation

@Dunqing
Copy link
Member

@Dunqing Dunqing commented May 15, 2025

According to len is more commonly used than cap and a is used less than any other field, reorder RawVec fields to get the best performance.

image

I've tried putting cap before len, the performance is not as good as the current order, see #11050 (comment)

Copy link
Member Author

Dunqing commented May 15, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions github-actions bot added the C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior label May 15, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented May 15, 2025

CodSpeed Instrumentation Performance Report

Merging #11050 will not alter performance

Comparing 05-15-refactor_allocator_vec2_reorder_rawvec_fields (5dcd0f1) with main (c60382d)

Summary

✅ 36 untouched benchmarks

@Dunqing
Copy link
Member Author

Dunqing commented May 15, 2025

#[repr(C)]
pub struct RawVec<'a, T> {
    ptr: NonNull<T>,
    cap: u32,
    pub(super) len: u32,
    a: &'a Bump,
}
image

@Dunqing Dunqing force-pushed the 05-15-refactor_allocator_vec2_reorder_rawvec_fields branch from 67d4c03 to f2e5a99 Compare May 15, 2025 09:38
@overlookmotel overlookmotel changed the base branch from 05-08-feat_allocator_vec2_change_len_from_usize_to_u32 to graphite-base/11050 May 15, 2025 22:06
@Dunqing Dunqing changed the title refactor(allocator/vec2): reorder RawVec fields perf(allocator/vec2): reorder RawVec fields May 15, 2025
@Dunqing Dunqing changed the title perf(allocator/vec2): reorder RawVec fields perf(allocator/vec2): reorder RawVec fields May 15, 2025
@github-actions github-actions bot added the C-performance Category - Solution not expected to change functional behavior, only performance label May 15, 2025
@Dunqing Dunqing force-pushed the 05-15-refactor_allocator_vec2_reorder_rawvec_fields branch from 9a30fb7 to 25c0469 Compare May 15, 2025 22:26
@Dunqing Dunqing force-pushed the graphite-base/11050 branch from 7c5d8af to c60382d Compare May 15, 2025 22:26
@Dunqing Dunqing changed the base branch from graphite-base/11050 to main May 15, 2025 22:26
@Dunqing Dunqing marked this pull request as ready for review May 15, 2025 22:28
Copilot AI review requested due to automatic review settings May 15, 2025 22:28
@Dunqing Dunqing requested a review from overlookmotel as a code owner May 15, 2025 22:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request reorders the RawVec fields to optimize performance by placing the most frequently accessed field (len) immediately after the pointer.

  • Updated the field offset constant in the raw transfer generator to reflect the new layout.
  • Reordered the struct fields in RawVec so that len now directly follows the pointer.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
tasks/ast_tools/src/generators/raw_transfer.rs Updated the constant offset for Vec's length field to match the new field ordering in RawVec.
crates/oxc_allocator/src/vec2/raw_vec.rs Reordered RawVec fields from the previous order to a new order (ptr, len, cap, a) to improve performance.
Comments suppressed due to low confidence (2)

tasks/ast_tools/src/generators/raw_transfer.rs:30

  • The VEC_LEN_FIELD_OFFSET value is updated to 8 to reflect the new field order in RawVec. Please verify that the adjusted offset aligns with all expected memory layout assumptions, especially regarding pointer size across architectures.
const VEC_LEN_FIELD_OFFSET: usize = 8;

crates/oxc_allocator/src/vec2/raw_vec.rs:70

  • Reordering the RawVec fields so that 'len' is placed immediately after the pointer should enhance performance. Confirm that this reordering is consistently reflected in all related code that relies on the struct layout.
cap: u32,

@overlookmotel overlookmotel added the 0-merge Merge with Graphite Merge Queue label May 15, 2025
Copy link
Member

overlookmotel commented May 15, 2025

Merge activity

According to `len` is more commonly used than `cap` and `a` is used less than any other field,  reorder `RawVec` fields to get the best performance.

<img width="721" alt="image" src="https://github.com/user-attachments/assets/c044e134-2d28-45a4-8d8d-91ec5166612f" />

I've tried putting `cap` before `len`, the performance is not as good as the current order, see #11050 (comment)
@graphite-app graphite-app bot force-pushed the 05-15-refactor_allocator_vec2_reorder_rawvec_fields branch from 25c0469 to 5dcd0f1 Compare May 15, 2025 22:33
@graphite-app graphite-app bot merged commit 5dcd0f1 into main May 15, 2025
26 checks passed
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label May 15, 2025
@graphite-app graphite-app bot deleted the 05-15-refactor_allocator_vec2_reorder_rawvec_fields branch May 15, 2025 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ast-tools Area - AST tools C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior C-performance Category - Solution not expected to change functional behavior, only performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants