Skip to content

Only load the taint store when there is something to mark - #222

Open
asamassekou10 wants to merge 1 commit into
PrismorSec:mainfrom
asamassekou10:perf/taint-lazy-load
Open

Only load the taint store when there is something to mark#222
asamassekou10 wants to merge 1 commit into
PrismorSec:mainfrom
asamassekou10:perf/taint-lazy-load

Conversation

@asamassekou10

Copy link
Copy Markdown
Contributor

Found this while profiling #27, but it's unrelated so I split it out.

_get_taint() reads the session's taint file from disk, and it was getting called on every evaluate() even though only events with a prompt-injection finding ever mark. So every other event paid a file read for nothing.

Checking the cheap in-memory condition first avoids that. The network block already loads the store lazily when it needs it, so taint just stays None otherwise.

On an 800-statement workload that's 1044 ms down to 378 ms, all of it from the removed reads. A benign event now does 0 taint reads instead of 1, and an injection event still does 1 and marks the same as before.

Nothing else changes: the same events mark, and taint escalation on network events is untouched. test_trifecta.py, test_suspicious_network and test_sarif_output all pass, and the CI security-regression suite is green.

Kept separate from #27 so it can be reviewed or reverted on its own. #27 doesn't depend on it. If #221 lands first this will need a trivial rebase on the same hunk, or vice versa.

_get_taint() reads the session's taint file from disk, but it was called
unconditionally on every evaluate() — while only events that carry a
prompt-injection finding ever mark. Every other event paid a file read
for nothing.

Test the cheap in-memory condition first and load the store only when it
will be used. The network-event block already lazily loads it when it
needs it, so `taint` is simply left None otherwise.

Measured on an 800-statement workload: 1044 ms -> 378 ms, entirely from
the removed reads. Behaviour is unchanged — marking still happens for
exactly the same events, and taint escalation on network events is
untouched.
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