Skip to content

Reuse immutable graph views across rule checks - #108

Draft
TristanKruse wants to merge 1 commit into
mainfrom
perf/rule-views-101
Draft

TristanKruse wants to merge 1 commit into
mainfrom
perf/rule-views-101

Conversation

@TristanKruse

@TristanKruse TristanKruse commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Closes #101. Builds on merged #107; targets main directly. No public fluent API or analysis-mode changes, no release/publication.

  • Attach three lazy immutable views (nodes/internal/external edges) to each existing cached analysis entry. File and layer checks share these pure projection outputs.
  • Keep selectors, assertions, cycle enumeration, custom FileInfo predicates, logging and custom/slice mapper closures per check. No query-result caching or new graph-identity global map.
  • Preserve the existing explicit snapshot contract. Matching clear_cache, global clearing, changed ignore/exclusion settings and CLI command resets get new views. In-flight rules may finish on their original immutable snapshot. The bundle cannot keep itself alive through a caller-held raw graph after cache clearing.

Regression evidence

  • CI full suite: 944 examples, zero failures on Ruby 3.3/3.4 Linux and Ruby 4.0 Windows (one platform-specific skip on Linux; all 944 execute on hosted Windows).
  • Linux runtime-only coverage: 98.89% lines / 92.68% branches; existing thresholds unchanged.
  • Full RuboCop: 354 files, no offenses.
  • New tests cover exact ordered structured violations/evidence in both moods, self/isolated/external edges, empty selections, lazy single computation, concurrent first use, failed projections, modes/load paths/exclusions, explicit/global/CLI invalidation, GC lifetime, stateful callbacks/labelers and logging isolation.

Performance methodology / tradeoff

Extend benchmark/study's existing fixture/oracle/measurement helpers, not a second benchmark framework. Fresh paired baseline/candidate processes use identical harness files; the baseline is merged #100 (e2d347e14e0f8d06489582bcb7c5473295a7df4b) to avoid attributing source-walker gains to this PR.

Measure graph-only, one rule, twenty identical rules and twenty genuinely different rules (7 file / 7 layer / 6 slice), with separate forbidden/empty controls. Report cold graph, a separate cold-plus-whole-suite, individual warm checks, allocation counts, post-GC retained Ruby heap and Linux lifetime peak RSS. Manual read-only pinned CI runs three alternating pairs per workload on Linux/Windows at 10,000 sources. Ordinary tests use four fixture pairs and no machine-speed gates.

Retained views add O(V+E) memory when requested (fixed three slots per existing cached analysis, not per rule); slices intentionally remain uncached because frozen Procs can still capture mutable state. Do not claim uniform gains for all policy types or a memory reduction.

Compatibility/quality/package, locked dependency security, the RAG fixture (36 examples), all four pinned real-world canaries, strict documentation validation (204 pages), all twelve installed-gem acceptance scripts and the original research/semantic study pass. The 10,000-source paired study is run 45446554405; Windows measurements are still in progress.

Linux three-trial medians (seconds), 10,000 sources:

Workload Cold graph + suite, baseline → candidate Warm suite, baseline → candidate Warm allocations, baseline → candidate
One boundary 1.983 → 2.010 0.0767 → 0.0255 255,209 → 70,193
20 identical 3.637 → 2.552 1.765 → 0.530 5,104,180 → 1,403,860
20 varied 3.669 → 2.995 1.815 → 0.939 5,541,790 → 3,236,581

Post-GC retained Ruby heap growth is ~6.66 → 9.83 MiB for indexed suites (about 3.17 MiB extra); graph-only growth differs by only a few hundred bytes. Peak RSS is not uniformly better: the repeated-suite median rises 139,448 → 154,672 KiB, while varied-suite medians are 150,124 → 148,852 KiB. Cold single-rule timing is ~1.3% higher in this Linux sample. These are shared-runner observations, not hard thresholds or claims of universal speed/memory improvements.

This branch has not been deployed

No deployments
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.

Performance: reuse immutable node and internal-edge views across rule checks

1 participant