Skip to content

Conversation

@Boshen
Copy link
Member

@Boshen Boshen commented Sep 28, 2025

Summary

This PR refactors the Token storage from Array of Structs (AoS) to Struct of Arrays (SoA) pattern to improve memory locality and cache utilization.

Changes

  • New Tokens struct: Implements SoA pattern with separate Vec fields for each token property

    • dst_lines, dst_cols, src_lines, src_cols, source_ids, name_ids
    • Provides methods for adding, accessing, and iterating over tokens
  • Updated modules:

    • SourceMapBuilder: Now builds tokens using the SoA structure
    • SourceMap: Stores and accesses tokens in SoA format
    • ConcatSourceMapBuilder: Works with SoA tokens for concatenation
    • encode module: Iterates over SoA structure for better cache locality
    • decode module: Populates SoA structure when parsing sourcemaps
  • Backward compatibility: The Token struct is still used in APIs, with conversion happening internally

Benefits

  • Better memory locality: Accessing specific fields (e.g., all dst_lines) is now cache-friendly
  • Improved performance: Sequential access patterns during encoding/decoding operations
  • Memory efficiency: Potential for better memory layout and reduced padding

Test Plan

All existing tests pass without modification, confirming backward compatibility.

🤖 Generated with Claude Code

…ality

- Add new Tokens struct using Struct of Arrays pattern with separate Vec fields
- Update SourceMapBuilder, SourceMap, and ConcatSourceMapBuilder to use Tokens
- Modify encode/decode modules to work with SoA structure
- Maintain backward compatibility by keeping Token struct for API
- Improve cache locality when accessing specific token fields during operations

This change improves memory access patterns, especially during encoding/decoding
operations where specific fields are accessed sequentially.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@graphite-app
Copy link

graphite-app bot commented Sep 28, 2025

How to use the Graphite Merge Queue

Add the label merge to this PR to add it to the merge queue.

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.

@codspeed-hq
Copy link

codspeed-hq bot commented Sep 28, 2025

CodSpeed Performance Report

Merging #179 will degrade performances by 15.81%

Comparing feat/tokens-soa (7e5a6f6) with main (3ac6b3f)

Summary

⚡ 1 improvement
❌ 4 regressions

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
from_json_string 17 µs 20 µs -15.11%
generate_lookup_table 1.3 µs 1.6 µs -15.81%
to_json 5.6 µs 6.2 µs -9.36%
to_json_string 5.3 µs 6 µs -10.67%
add_name_add_source_and_content 1.7 µs 1.6 µs +5.49%

@Boshen Boshen closed this Sep 28, 2025
@Boshen Boshen deleted the feat/tokens-soa branch September 28, 2025 08:10
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.

2 participants