[PR #1457] [MERGED] perf(javascript): hash each semantic evidence context once #2899

Closed
opened 2026-10-17 21:11:33 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/1457
Author: @kaoru0822-kitauji
Created: 10/10/2026
Status: ✅ Merged
Merged: 10/10/2026
Merged by: @kaoru0822-kitauji

Base: main ← Head: perf/javascript-intern-evidence-contexts


📝 Commits (1)

  • 8b98c1b perf(javascript): hash each semantic evidence context once

📊 Changes

2 files changed (+55 additions, -8 deletions)

View changed files

📝 src/domain/javascript/javascriptSemanticGraph.ts (+15 -8)
📝 src/domain/javascript/javascriptSemanticGraphQuery.test.ts (+40 -0)

📄 Description

Summary

JavaScriptSemanticEvidenceContextRegistry.intern runs once for every semantic node, relation, unknown and fingerprint. Each call canonicalized the full non-location provenance context three times: once to SHA-256 it into jsrg_evidence_…, then twice to compare the stored row against the new one for a digest collision. A file has only a handful of distinct contexts, so almost all of that work recomputed a known answer.

The registry now keys contexts by their canonical text:

  • Each fact canonicalizes its context once. A known context returns its interned ID without hashing.
  • A new context is hashed with the same evidenceContextId as before. If a different context already holds that digest, the registry still throws the digest-collision error.
  • The context table, IDs, resolve and output are unchanged.

Measurements

rea analyze-javascript-application /Applications/Obsidian.app/Contents/Resources/obsidian.asar --format json on an M-series Mac with Node 26, wall time without a profiler:

Build Runs Wall time
main 33b9b31a 46.8 s, 47.1 s ~47.0 s
this branch 44.4 s, 44.2 s, 44.7 s ~44.4 s

That is about 5.5% faster. The 333,758,952-byte Evidence is byte-identical (same SHA-256). In CPU profiles, inclusive time in intern dropped from about 3.5 s to about 1.2 s.

Verification

  • New registry test: repeated context yields the same ID with its own location; duplicate/unsorted limitations normalize to the same context; distinct contexts get distinct IDs; the ID equals jsrg_evidence_ + digestCanonicalValue(context); the context table has one row per distinct context; resolve round-trips. It passes against both the old and new implementations.
  • npm run check:changed (57 files, 595 tests) and npm run typecheck pass.

Refs #1065.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/1457 **Author:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Created:** 10/10/2026 **Status:** ✅ Merged **Merged:** 10/10/2026 **Merged by:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Base:** `main` ← **Head:** `perf/javascript-intern-evidence-contexts` --- ### 📝 Commits (1) - [`8b98c1b`](https://github.com/morluto/rea/commit/8b98c1b6b407bd2346f18b9043d297c49d4540cb) perf(javascript): hash each semantic evidence context once ### 📊 Changes **2 files changed** (+55 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `src/domain/javascript/javascriptSemanticGraph.ts` (+15 -8) 📝 `src/domain/javascript/javascriptSemanticGraphQuery.test.ts` (+40 -0) </details> ### 📄 Description ## Summary `JavaScriptSemanticEvidenceContextRegistry.intern` runs once for every semantic node, relation, unknown and fingerprint. Each call canonicalized the full non-location provenance context three times: once to SHA-256 it into `jsrg_evidence_…`, then twice to compare the stored row against the new one for a digest collision. A file has only a handful of distinct contexts, so almost all of that work recomputed a known answer. The registry now keys contexts by their canonical text: - Each fact canonicalizes its context once. A known context returns its interned ID without hashing. - A new context is hashed with the same `evidenceContextId` as before. If a different context already holds that digest, the registry still throws the digest-collision error. - The context table, IDs, `resolve` and output are unchanged. ## Measurements `rea analyze-javascript-application /Applications/Obsidian.app/Contents/Resources/obsidian.asar --format json` on an M-series Mac with Node 26, wall time without a profiler: | Build | Runs | Wall time | |---|---|---| | main `33b9b31a` | 46.8 s, 47.1 s | ~47.0 s | | this branch | 44.4 s, 44.2 s, 44.7 s | ~44.4 s | That is about 5.5% faster. The 333,758,952-byte Evidence is byte-identical (same SHA-256). In CPU profiles, inclusive time in `intern` dropped from about 3.5 s to about 1.2 s. ## Verification - New registry test: repeated context yields the same ID with its own location; duplicate/unsorted limitations normalize to the same context; distinct contexts get distinct IDs; the ID equals `jsrg_evidence_` + `digestCanonicalValue(context)`; the context table has one row per distinct context; `resolve` round-trips. It passes against both the old and new implementations. - `npm run check:changed` (57 files, 595 tests) and `npm run typecheck` pass. Refs #1065. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-17 21:11:33 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#2899
No description provided.