Skip to content

Use single allocation to store origin and QueryRevisionExtra#1112

Merged
MichaReiser merged 7 commits into
salsa-rs:masterfrom
MichaReiser:micha/co-allocate-query-revision-extras
Jun 10, 2026
Merged

Use single allocation to store origin and QueryRevisionExtra#1112
MichaReiser merged 7 commits into
salsa-rs:masterfrom
MichaReiser:micha/co-allocate-query-revision-extras

Conversation

@MichaReiser

@MichaReiser MichaReiser commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

With #1101, the layout for a memo with extra data is:

QueryRevisions
+--------------------------------------+
| changed_at                           |
| durability / flags                   |
|                                      |
| OriginAndExtra (13 bytes)            |
| +----------+----------+------------+ |
| | tag      | payload  | metadata   | |
| | Indirect | pointer  |     0      | |
| +----------+----|-----+------------+ |
+-----------------|--------------------+
                  |
                  v
        Box<IndirectOriginAndExtra>
        +----------------------------------+
        | origin: OriginAndExtra           |
        | +----------+----------+--------+ |
        | | Direct   | pointer -+ | count| |
        | +----------+----------|-+------+ |
        |                       |          |
        | extra (24 bytes)      |          |
        | +------------------+  |          |
        | | tracked IDs      |  |          |
        | | cycle heads      |  |          |
        | | iteration/flags  |  |          |
        | +------------------+  |          |
        +-----------------------|----------+
                                |
                                v
                           Box<[E]>
                           +-----+-----+-----+-----+
                           | E 0 | E 1 | E 2 | ... |
                           +-----+-----+-----+-----+

Allocations: 2
  1. IndirectOriginAndExtra, approximately 40 bytes
  2. Edge slice, sizeof(E) * edge_count

Note how this requires two boxes. One to IndirectOriginAndExtra and another for the query edges.

This PR avoids the two boxes by using a custom DST that stores the QueryRevisionExtra as Header and the origin edges as slice, both using the same Box

QueryRevisions
+--------------------------------------+
| changed_at                           |
| durability / flags                   |
|                                      |
| OriginAndExtra (13 bytes)            |
| +------------+----------+----------+ |
| | tag        | payload  | metadata | |
| | With extra | pointer  | count    | |
| | Packed/Wide|    |     |          | |
| +------------+----|-----+----------+ |
+-------------------|------------------+
                    |
                    v
       SliceWithHeader<QueryRevisionsExtraInner, E>
       +--------------------+-----+-----+-----+-----+
       | extra (24 bytes)   | E 0 | E 1 | E 2 | ... |
       |                    |     |     |     |     |
       | tracked IDs        |     inline edges      |
       | cycle heads        |                       |
       | iteration/flags    |                       |
       +--------------------+-----------------------+

The memory gains on ty are marginal, but walltime of cycle heavy projects improve by 10% (20% fewer allocations)!
astral-sh/ruff#25774

@MichaReiser MichaReiser changed the title Encapsulate query revision origins Use single allocation to store origin and QueryRevisionExtra Jun 8, 2026
@netlify

netlify Bot commented Jun 8, 2026

Copy link
Copy Markdown

Deploy Preview for salsa-rs canceled.

Name Link
🔨 Latest commit 072d3ae
🔍 Latest deploy log https://app.netlify.com/projects/salsa-rs/deploys/6a27051ac8836f00093d73a8

@netlify

netlify Bot commented Jun 8, 2026

Copy link
Copy Markdown

Deploy Preview for salsa-rs canceled.

Name Link
🔨 Latest commit bf11195
🔍 Latest deploy log https://app.netlify.com/projects/salsa-rs/deploys/6a2915513b582500081fd9c8

@MichaReiser MichaReiser force-pushed the micha/co-allocate-query-revision-extras branch from 072d3ae to 1e0667c Compare June 8, 2026 18:27
@codspeed-hq

codspeed-hq Bot commented Jun 8, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 5.79%

⚡ 2 improved benchmarks
✅ 24 untouched benchmarks

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory converge_diverge 9.1 KB 8.6 KB +6.28%
Simulation converge_diverge 170.5 µs 161.9 µs +5.3%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing MichaReiser:micha/co-allocate-query-revision-extras (bf11195) with master (f6325bb)

Open in CodSpeed

@MichaReiser MichaReiser force-pushed the micha/co-allocate-query-revision-extras branch 4 times, most recently from 0f537ff to eba3425 Compare June 9, 2026 07:07
@MichaReiser MichaReiser force-pushed the micha/co-allocate-query-revision-extras branch 11 times, most recently from 262e64c to f26c8f5 Compare June 9, 2026 09:09
@MichaReiser MichaReiser force-pushed the micha/co-allocate-query-revision-extras branch from f26c8f5 to 42c6788 Compare June 9, 2026 09:18
@MichaReiser MichaReiser force-pushed the micha/co-allocate-query-revision-extras branch from 42c6788 to 918c48c Compare June 9, 2026 09:33
@MichaReiser MichaReiser marked this pull request as ready for review June 9, 2026 09:41

@carljm carljm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks reasonable to me! Neat optimization.

Comment thread src/zalsa_local.rs
Comment thread src/active_query.rs Outdated
@MichaReiser MichaReiser added this pull request to the merge queue Jun 10, 2026
Merged via the queue into salsa-rs:master with commit 768348e Jun 10, 2026
12 checks passed
@MichaReiser MichaReiser deleted the micha/co-allocate-query-revision-extras branch June 10, 2026 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants