Skip to content

perf: avoid type checks in memo and field lookups#1174

Draft
MichaReiser wants to merge 11 commits into
salsa-rs:masterfrom
MichaReiser:optimize-memo-lookup
Draft

perf: avoid type checks in memo and field lookups#1174
MichaReiser wants to merge 11 commits into
salsa-rs:masterfrom
MichaReiser:optimize-memo-lookup

Conversation

@MichaReiser

@MichaReiser MichaReiser commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Memo and field lookups repeated TypeId checks even though the database-bound ingredient fixes the accessed type. Bind each ingredient to its database context and acquire thread-local state only for operations that need it.

Fixed hot memo hits drop from 233 to 228 instructions (-2.15%), untracked tracked-struct field bodies drop from 59 to 58, CodSpeed reports a 6.76% aggregate improvement, and ty's 29-case suite improves by 0.145% weighted overall.

Testing: Full target, manual-registration, lint, and performance suites passed.

@netlify

netlify Bot commented Jun 21, 2026

Copy link
Copy Markdown

Deploy Preview for salsa-rs canceled.

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

@codspeed-hq

codspeed-hq Bot commented Jun 21, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by ×3.3

⚡ 8 improved benchmarks
❌ 5 regressed benchmarks
✅ 61 untouched benchmarks
⏩ 12 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation cold_execute 1.6 ms 1.9 ms -14.72%
WallTime parallel_fast_path[NoEviction] 365.4 µs 423.4 µs -13.7%
WallTime project_check_then_incremental[NoEviction] 6 ms 6.9 ms -11.8%
WallTime parallel_fast_path[Lru] 3.7 ms 4.1 ms -9.33%
WallTime project_check_then_incremental[Lru] 9.9 ms 10.8 ms -8.22%
Simulation intern_distinct_many 24,550.2 µs 128.3 µs ×190
Simulation tracked_reuse_few 3,604.1 µs 102.2 µs ×35
Simulation tracked_reuse_many 986.3 µs 83.8 µs ×12
Simulation untracked_field_read_many 1,281.9 µs 217.7 µs ×5.9
Simulation tracked_field_read_many 1,260.7 µs 266.6 µs ×4.7
Simulation input_field_read_many 559.8 µs 257.6 µs ×2.2
Simulation interned_field_read_many 324.9 µs 211.1 µs +53.91%
Simulation fill_and_evict[Lru] 548.8 µs 442.1 µs +24.16%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing MichaReiser:optimize-memo-lookup (1914bcd) with master (af2381a)

Open in CodSpeed

Footnotes

  1. 12 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@MichaReiser

Copy link
Copy Markdown
Contributor Author

This is cool but I don't think codex's reasoning here is safe. The issue is that zalsa could be smuggled in. So we'd have to make fetch unsafe.

@MichaReiser MichaReiser force-pushed the optimize-memo-lookup branch from 6d04b76 to e16c18e Compare June 30, 2026 19:54
@MichaReiser MichaReiser changed the title perf: avoid type check in memo lookup perf: avoid type checks in memo and field lookups Jul 5, 2026
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