You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf: per-character Python loops in the Unicode security view dominate analysis (~20 KB/s) #866
Environment: SkillSpector main cf5cac7 (version string 2.12.0), Python 3.12, macOS, --no-llm. Profiled on a 71-file, 431 KB skill.
cProfile of a scan: 21.7 s user / 29 s wall (54.9 s under tracing). The cost is the Unicode security-view machinery, not the rule regexes:
Where
tottime
artifacts.py
19.0 s
security_reconstruction.py
6.9 s
static_runner.py
5.4 s
all static_patterns_* rule code
< 1.5 s
YARA
0.26 s
Call counts: _has_security_word_character_before 1.53M, _fold_security_character 1.93M, _security_skeleton_piece 2.27M, re.search 1.57M, str.translate 4.3M, len 37M, reached from _obfuscated_action_completions and _obfuscated_instruction_matches. No OSV/network time in this scan.
Suggest a precompiled str.translate table, regexes instead of per-character loops, and an early exit when a text has no non-ASCII or confusable characters.
We observed similar security-text preprocessing costs and experimented with scan-scoped reuse of completed security_text_views() results. Sharing our measurements as a potential complementary improvement to #907, and we'd appreciate your feedback.
Multiple analyzers request transformations of the same text, including source-offset mappings. Our approach reuses those completed results across analyzer workers within the same scan. This reduces repeated preprocessing and could complement the ASCII fast paths introduced in #907.
Local experiment
We tested a 45-file bundle (~1.04 MiB uncompressed, including 44 text files) on Windows with Python 3.13.12.
With LLM analysis disabled and the same bundle and analyzer configuration, graph execution time excluding imports was:
Run
Baseline
With preprocessing reuse
1
96.8 s
54.6 s
2
100.7 s
58.6 s
Static scan time decreased by approximately 42–44% on this bundle. All four runs reported 36 findings.
Peak accounted cache retention in the prototype was approximately 16.6 MiB. This measures retained cache structures, not a process RSS increase.
These measurements come from an earlier local prototype on one bundle. Performance against current main and across additional bundles still needs evaluation. The reported improvement applies to static scanning; end-to-end scans with LLM analysis require separate measurement.
Implementation considerations
Our internal implementation:
Creates a separate cache for each scan, shared across its analyzer workers.
Limits retained bytes and entry count, bypassing retention for oversized results.
Coordinates concurrent builders of the same text.
Retains deadline/cancellation checks on cache hits and while waiting.
Caches completed results only.
Releases the cache on normal completion, exceptions, cancellation, and early stream closure.
The change focuses on preprocessing reuse, with analyzer rules and inspection scope unchanged.
Would a focused follow-up PR for scan-scoped preprocessing reuse be welcome? Is there existing work in this area that we should coordinate with?
Thanks for the measurements, @jh49choi. From my side as the author of #907, I think this is worth a focused follow-up PR. #907 makes an individual fold cheaper; your proposal avoids doing the same work again in another analyzer. The ~2.42× figure from #907 was a helper microbenchmark, so I’d keep it separate from your static graph timings.
One PR I’d coordinate with is #583. On main at a09091e, we cache some predicates and token-gap spans, but not the completed security_text_views() tuple. I confirmed that two deadline-aware calls on the same office input still build the normalized view twice. #583 proposes caching the normalized view itself and bypasses that cache for callers with a runtime callback. It would be worth agreeing on which layer retains the view before adding a second retention budget.
I’d key on the exact string passed to the helper, including any context prefix, and leave file/window rebasing and JSON source mapping to the caller. office and office are a useful regression pair: they can produce the same visible text but have different source offsets. The offset arrays also need to stay read-only across consumers even though the view dataclass is frozen.
For review, the most useful evidence to me would be:
A cache-on/off comparison on the same current main, using your original bundle plus a low-reuse ASCII case and a Unicode/JSON-heavy case. Median static graph time, actual builds avoided, accounted cache bytes, and peak process RSS would show both the benefit and its cost.
A diff of the structured reports, ignoring only documented nondeterminism such as timestamps and generated IDs. I’d compare evidence and source ranges, scores, and inspection completeness, not just the 36-finding count.
A small concurrency test for the lifecycle you described: two workers requesting one key, a waiter whose deadline expires, and a builder that exits before publishing. Closing one scan early while another remains active would also be a useful isolation check.
The 42–44% reduction on that bundle is a good reason to pursue this without assuming the same gain end to end. I don’t see a conflict with #907 itself; I’d welcome the #583 author’s and maintainers’ thoughts on the cache boundary.
Thanks @longfie for the feedback and the opportunity to contribute. I built a local prototype on top of NVIDIA/SkillSpector main at a09091e and reran the 45-file bundle from my earlier comment.
What I changed
In artifacts.py, multiple analyzers could call security_text_views() with the same text during a scan, and each call would rebuild the views and their source mappings. I moved the existing builder into _build_security_text_views() and added a cache lookup before it. The key is the exact input string, including any context prefix. Each caller gets private copies of source_offsets and source_end_offsets so adjusting a source location in one analyzer cannot change another analyzer’s evidence.
In security_text_cache.py, workers requesting the same input can share one completed build. Each waiting worker still checks its own deadline. If the builder fails or is interrupted, the cache wakes the waiters and discards the partial result. The cache holds up to 1,024 entries within a 64 MiB budget that counts input keys, views, offset buffers and entry overhead.
In graph.py and scan_graph.py, I tied the cache to one graph execution. Parallel workers in a scan share it, concurrent scans have separate caches, and the graph releases the entries on completion, failure, cancellation or early stream closure.
Environment and benchmark
I ran this on Windows 11 Enterprise x64 (build 26200), with an Intel Core Ultra 7 155H (16 cores, 22 logical processors), 32 GiB RAM, CPython 3.12.13 and LangGraph 1.2.20. Both configurations used the same prototype and view builder. For the cache-off runs, I disabled the graph wrapper.
For each input I ran three pairs in alternating order (off/on, on/off, off/on), starting a fresh process each time. I timed graph execution after imports, set PYTHONHASHSEED=0, used local inputs and disabled the LLM. Both configurations used the same HTTPX mock transport to make OSV unavailable. In an earlier trial, normal TLS/proxy setup was still active. The first pair took 86.5 s off and 93.1 s on, and later OSV timeouts changed the report. That prompted the controlled rerun below.
Input
Cache off, median (range)
Cache on, median (range)
View builds, off → on
Findings per run
Original bundle, 45 files / 1.04 MiB
138.05 s (130.63–149.71)
67.31 s (65.02–101.87)
1,698 → 466
65
Unicode/JSON control, 5 files
22.05 s (21.32–22.70)
13.27 s (12.43–13.34)
140 → 15
12
Short ASCII control, 11 files
2.16 s (1.92–2.45)
1.80 s (1.75–2.05)
298 → 23
0
Median scan time fell 51.2% on the original bundle and 39.8% on the Unicode/JSON control. On the original bundle, cumulative builder CPU time fell from 45.31 s to 2.47 s. Peak parent-process RSS was 255.09 MiB off and 253.94 MiB on. The cache itself peaked at 17.47 MiB of accounted storage and reported zero retained bytes after close. A separate short-ASCII run took 1.17 s off and 1.50 s on, so the effect on small inputs is still unclear.
Correctness and regression tests
I compared all 18 full JSON reports. Within each dataset, all six matched after normalizing scan timestamps, generated finding IDs and the order of explicitly unordered rows. The comparison included evidence, source positions, scores, severity, coverage and limitations. On the original bundle, both configurations fully inspected 41 files, partially inspected three and left one uninspected.
The targeted unit and integration run passed 187 tests, with one skipped. The 25 new cases cover offset mutation, concurrent requests for the same text, cache limits, caller deadlines, failed builders, cancellation, step timeouts and overlapping sync/async scans. All 25 also passed against the built wheel. Full-suite and Linux CI validation are still open. On Windows, I reproduced an existing CLI safe-file-output failure on the clean base commit.
@smoy@longfie, how would you prefer to handle the overlap with #583? My prototype retains the completed views for one scan, while #583 caches normalized views. I’d be happy to adapt this before opening a PR so there’s one place responsible for retaining those buffers.
Activity
perf(security): avoid Unicode folding for ASCII characters (#907)
jh49choi commentedon Nov 3, 2026
@naamanhirschfeld-armis @longfie @rng1995
We observed similar security-text preprocessing costs and experimented with scan-scoped reuse of completed
security_text_views()results. Sharing our measurements as a potential complementary improvement to #907, and we'd appreciate your feedback.Multiple analyzers request transformations of the same text, including source-offset mappings. Our approach reuses those completed results across analyzer workers within the same scan. This reduces repeated preprocessing and could complement the ASCII fast paths introduced in #907.
Local experiment
We tested a 45-file bundle (~1.04 MiB uncompressed, including 44 text files) on Windows with Python 3.13.12.
With LLM analysis disabled and the same bundle and analyzer configuration, graph execution time excluding imports was:
Static scan time decreased by approximately 42–44% on this bundle. All four runs reported 36 findings.
Peak accounted cache retention in the prototype was approximately 16.6 MiB. This measures retained cache structures, not a process RSS increase.
These measurements come from an earlier local prototype on one bundle. Performance against current main and across additional bundles still needs evaluation. The reported improvement applies to static scanning; end-to-end scans with LLM analysis require separate measurement.
Implementation considerations
Our internal implementation:
The change focuses on preprocessing reuse, with analyzer rules and inspection scope unchanged.
Would a focused follow-up PR for scan-scoped preprocessing reuse be welcome? Is there existing work in this area that we should coordinate with?
longfie commentedon Nov 17, 2026
Thanks for the measurements, @jh49choi. From my side as the author of #907, I think this is worth a focused follow-up PR. #907 makes an individual fold cheaper; your proposal avoids doing the same work again in another analyzer. The ~2.42× figure from #907 was a helper microbenchmark, so I’d keep it separate from your static graph timings.
One PR I’d coordinate with is #583. On
mainata09091e, we cache some predicates and token-gap spans, but not the completedsecurity_text_views()tuple. I confirmed that two deadline-aware calls on the sameofficeinput still build the normalized view twice. #583 proposes caching the normalized view itself and bypasses that cache for callers with a runtime callback. It would be worth agreeing on which layer retains the view before adding a second retention budget.I’d key on the exact string passed to the helper, including any context prefix, and leave file/window rebasing and JSON source mapping to the caller.
officeandofficeare a useful regression pair: they can produce the same visible text but have different source offsets. The offset arrays also need to stay read-only across consumers even though the view dataclass is frozen.For review, the most useful evidence to me would be:
main, using your original bundle plus a low-reuse ASCII case and a Unicode/JSON-heavy case. Median static graph time, actual builds avoided, accounted cache bytes, and peak process RSS would show both the benefit and its cost.The 42–44% reduction on that bundle is a good reason to pursue this without assuming the same gain end to end. I don’t see a conflict with #907 itself; I’d welcome the #583 author’s and maintainers’ thoughts on the cache boundary.
jh49choi commentedon Nov 18, 2026
Thanks @longfie for the feedback and the opportunity to contribute. I built a local prototype on top of
NVIDIA/SkillSpectormain ata09091eand reran the 45-file bundle from my earlier comment.What I changed
In
artifacts.py, multiple analyzers could callsecurity_text_views()with the same text during a scan, and each call would rebuild the views and their source mappings. I moved the existing builder into_build_security_text_views()and added a cache lookup before it. The key is the exact input string, including any context prefix. Each caller gets private copies ofsource_offsetsandsource_end_offsetsso adjusting a source location in one analyzer cannot change another analyzer’s evidence.In
security_text_cache.py, workers requesting the same input can share one completed build. Each waiting worker still checks its own deadline. If the builder fails or is interrupted, the cache wakes the waiters and discards the partial result. The cache holds up to 1,024 entries within a 64 MiB budget that counts input keys, views, offset buffers and entry overhead.In
graph.pyandscan_graph.py, I tied the cache to one graph execution. Parallel workers in a scan share it, concurrent scans have separate caches, and the graph releases the entries on completion, failure, cancellation or early stream closure.Environment and benchmark
I ran this on Windows 11 Enterprise x64 (build 26200), with an Intel Core Ultra 7 155H (16 cores, 22 logical processors), 32 GiB RAM, CPython 3.12.13 and LangGraph 1.2.20. Both configurations used the same prototype and view builder. For the cache-off runs, I disabled the graph wrapper.
For each input I ran three pairs in alternating order (off/on, on/off, off/on), starting a fresh process each time. I timed graph execution after imports, set
PYTHONHASHSEED=0, used local inputs and disabled the LLM. Both configurations used the same HTTPX mock transport to make OSV unavailable. In an earlier trial, normal TLS/proxy setup was still active. The first pair took 86.5 s off and 93.1 s on, and later OSV timeouts changed the report. That prompted the controlled rerun below.Median scan time fell 51.2% on the original bundle and 39.8% on the Unicode/JSON control. On the original bundle, cumulative builder CPU time fell from 45.31 s to 2.47 s. Peak parent-process RSS was 255.09 MiB off and 253.94 MiB on. The cache itself peaked at 17.47 MiB of accounted storage and reported zero retained bytes after close. A separate short-ASCII run took 1.17 s off and 1.50 s on, so the effect on small inputs is still unclear.
Correctness and regression tests
I compared all 18 full JSON reports. Within each dataset, all six matched after normalizing scan timestamps, generated finding IDs and the order of explicitly unordered rows. The comparison included evidence, source positions, scores, severity, coverage and limitations. On the original bundle, both configurations fully inspected 41 files, partially inspected three and left one uninspected.
The targeted unit and integration run passed 187 tests, with one skipped. The 25 new cases cover offset mutation, concurrent requests for the same text, cache limits, caller deadlines, failed builders, cancellation, step timeouts and overlapping sync/async scans. All 25 also passed against the built wheel. Full-suite and Linux CI validation are still open. On Windows, I reproduced an existing CLI safe-file-output failure on the clean base commit.
@smoy @longfie, how would you prefer to handle the overlap with #583? My prototype retains the completed views for one scan, while #583 caches normalized views. I’d be happy to adapt this before opening a PR so there’s one place responsible for retaining those buffers.
Prototype branch: perf/scan-scoped-security-text-cache