Skip to content

perf(analysis-view): retain frozen snapshots across parent readers and index view lookups - #13315

Merged
morluto merged 2 commits into
mainfrom
perf/analysis-view-immutable-and-indexes
Nov 22, 2026
Merged

morluto merged 2 commits into
mainfrom
perf/analysis-view-immutable-and-indexes

Conversation

@morluto

@morluto morluto commented Nov 22, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes createAnalysisViewResultReader discarding the frozen JSON snapshot it just created, extends immutable snapshot caching to 10 uncached view parent readers, adds secondary WeakMap indexes for JavaScript module/fact views and PCAP DNS queries, and eliminates redundant route filtering passes:

  1. Retain frozen snapshot in createAnalysisViewResultReader (analysisViewParent.ts): Binds const frozen = freezeOwnedJsonTreeSnapshot(normalized.data) as Value, caches checked.set(source, frozen), and returns ok(frozen) rather than caching/returning the mutable pre-freeze parsed.value.
  2. Wrap uncached parent readers in createAnalysisViewResultReader:
    • Wrapped safeParseJavaScriptParent, byteEntropySchema, safeParseOwnedBinaryLayout, and functionDossierSchema in analysisView.ts.
    • Wrapped safeParseOwnedWebNetworkCapture in webNetworkCaptureView.ts so repeated summary/capture/protobuf/qlog calls share one immutable snapshot (enabling protobufCaptureView's isImmutableJsonSnapshot(report) fast path even when canBorrowParsedJsonSnapshot is false) and computed summarizeProtobuf(report.records) once in summary.
    • Wrapped captureSchema in pcapCaptureView.ts, plus read-only/JSON-safe parsers across managedArtifactView.ts, machoView.ts, dartAotView.ts, wasmArtifactView.ts, evmInterfaceView.ts, commandObservationView.ts, and fridaSessionStatusView.ts.
  3. Secondary WeakMap indexes & single-pass pagination:
    • javascriptApplicationView.ts: WeakMap-indexed moduleEntries, byNodeId, nodesByPath, and nodesByKind keyed on immutable snapshots (isImmutableJsonSnapshot(analysis)), forwarding immutable cacheOwner to projectJavaScriptFacts.
    • javascriptFactsView.ts: WeakMap-indexed all, byKind, byPath, and byKindAndPath keyed on sealed (cacheOwner, Object.isFrozen(nodes)), slicing O(page) or preserving Uint32Array-sorted order for multi-bucket filters.
    • pcapCaptureView.ts: added selectDnsQuery (capture.dns_queries[view.query_index] O(1) lookup), equalLabelsHex (removing JSON.stringify), and sealed dnsQueriesByName WeakMap.
    • javascriptRoutesView.ts: single-pass deliver loop counting total and skipping outside [page.offset, page.offset + page.limit) without intermediate .filter(...) array allocations.

Problem and expected behavior

  • createAnalysisViewResultReader froze normalized.data only to discard it and return mutable parsed.value, breaking downstream isImmutableJsonSnapshot(...) fast paths; 10 parent readers re-parsed the full parent Evidence JSON on every view/page request; and JS/PCAP views performed repeated linear scans per lookup.
  • Expected behavior: bit-identical view outputs, pagination totals/items, diagnostics, and unsealed fallback behavior with O(1)/O(page) warm reads and shared immutable parent snapshots.

Change and scope

  • Modified 14 production TS files in src/domain/analysisView/ and 5 test files (analysisViewParent.test.ts, protobufCaptureView.test.ts, pcapCaptureView.test.ts, analysisView.test.ts, javascriptRoutesView.test.ts).
  • Left analysisViewResult.ts and *SummaryViewResultSchema exports untouched.

Follow the contribution scope.
Not applicable (internal AnalysisView snapshot-sharing and read-only indexing within existing Evidence/contract boundaries).

Contract and boundary impact

  • Semantic owner and earliest changed stage: analysisViewParent.ts (createAnalysisViewResultReader) and view projectors in src/domain/analysisView/.
  • Contribution scope fit and linked maintainer decision: not applicable.
  • CLI and MCP/tool-catalog contract: none.
  • Provider, bridge, target-format, or platform compatibility: preserved (pcapRetainedView.test.ts platform-skipped locally on darwin as on main).
  • Evidence, artifact, provenance, or reconstruction contract: preserved (identical projected items, totals, and immutability guarantees; WeakMap indexes attach strictly to frozen isImmutableJsonSnapshot owners).
  • Target selection, authority, upstream behavior, and cleanup details: not applicable.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated:
    • analysisViewParent.test.ts: asserts createAnalysisViewResultReader returns an isImmutableJsonSnapshot === true frozen snapshot even when borrowing is rejected and hits WeakMap (parseCount === 1).
    • protobufCaptureView.test.ts: verifies single parse across summary, two protobuf pages, and capture preview plus sealed/unsealed parity.
    • pcapCaptureView.test.ts: verifies single captureSchema.safeParse across 6 views + query_index and query_labels_hex parity.
    • analysisView.test.ts: verifies WeakMap reuse & parity for javascriptApplicationView, javascriptFactsView, inspect_byte_entropy, and analyze_function.
    • javascriptRoutesView.test.ts: verifies route filter/ID pagination parity across skipped offsets.
  • Base reproduction or other evidence (compiled dist/, Apple M5 arm64, Node v24.22.1):
    • pcap_dns_addresses_by_query_index (200 iters): warm 302.534ms -> 1.946ms (155x)
    • pcap_dns_addresses_by_query_labels (200 iters): warm 271.418ms -> 2.142ms (127x)
    • web_network_capture_normalized_protobuf_fields (50 iters): warm 439.107ms -> 10.007ms (43.9x)
    • byte_entropy_summary (50 iters): warm 43.387ms -> 1.265ms (34.3x)
    • js_app_module_page_filtered_by_path (100 iters): warm 35.280ms -> 2.773ms (12.7x)
    • js_app_item_by_path (100 iters): warm 38.618ms -> 4.652ms (8.3x)
    • js_app_item_by_node_id (100 iters): warm 39.345ms -> 5.119ms (7.7x)
    • js_facts_filtered_kind_and_path (100 iters): warm 21.103ms -> 4.440ms (4.8x)
    • web_network_capture_summary (50 iters): warm 5.126ms -> 1.342ms (3.8x)
  • User-visible CLI/MCP output (if applicable): identical view schemas/results.
  • Remaining proof gaps: pcapRetainedView.test.ts is platform-skipped without Linux fixture prerequisites on darwin.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npx oxfmt on all 19 modified files — passed
  • npm run check:fast — passed (typecheck, lint, verify:architecture-guards across 2944 source files)
  • npm run build:cached — passed
  • npm run test:local -- src/domain/analysisView/*.test.ts — 74/74 files, 1,580/1,580 passed
  • npm run test:local -- src/application/analysisView/*.test.ts — 8/8 files, 130/130 passed
  • npm run test:focused (analysisViewMcp.test.ts 35/35; analysisViewCli.test.ts 31/31, javascriptFactsViewMcp.test.ts 2/2, javascriptAnalysisResources.test.ts 3/3 outside sandbox; pcapRetainedView.test.ts 1 skipped on darwin) — passed

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: Node v24.22.1 domain/application/MCP unit and boundary suites on darwin.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: all WeakMap indexes attach strictly to verified frozen immutable snapshots (isImmutableJsonSnapshot) with zero mutation.

Author readiness

Human owner:

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T04:31:19.050528Z 41f7ee5 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the previous performance issue is fixed and no new blocking issues were found.

Summary

This PR retains frozen parent snapshots and adds indexes for repeated view reads. The latest changes replace the full sort for filtered JavaScript facts with an ordered merge and a shortcut for large offsets.

  • Analysis views reuse frozen parent snapshots across repeated reads.
  • JavaScript module lookups and pages reuse indexes keyed to immutable analyses.
  • JavaScript fact pages reuse indexes for kind and path filters.
  • PCAP DNS address views find queries through cached capture indexes.
  • JavaScript route pages count matches while selecting the requested page.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Parent result] --> B{Sealed immutable snapshot?}
  B -->|No| C[Parse and scan]
  B -->|Yes| D[Reuse validated frozen snapshot]
  D --> E[Reuse fact indexes]
  E --> F{Matching buckets}
  F -->|One| G[Read requested slice]
  F -->|Several| H[Seek for large offsets]
  H --> I[Merge ordered positions]
  G --> J[Build requested rows]
  I --> J
  C --> J
Loading

Reviews (3) · Last reviewed commit: "perf(analysis-view): use bounded k-way m..." · Reviewed by Greptile

@morluto
morluto merged commit 1854918 into main Nov 22, 2026
41 checks passed
@morluto
morluto deleted the perf/analysis-view-immutable-and-indexes branch November 22, 2026 08:10
@morluto morluto added area: evidence Evidence, artifacts, and reconstruction performance Performance regressions, scaling limits, and bounded-resource work labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: evidence Evidence, artifacts, and reconstruction performance Performance regressions, scaling limits, and bounded-resource work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant