Repository navigation
perf(store): skip the sweep entirely when there is nothing to sweep - #344
alisemut0711-dev wants to merge 1 commit into
Conversation
442824b to
2341055
Compare
|
Filed #322; flagging a staleness problem here rather than opening anything competing — this is the approach I'd want to see land. The baseline bump is against numbers that have moved. This sets
Every core file now sits exactly at its cap — zero headroom anywhere. So the patch needs +4 on both, not the +4-from-841 this bump assumes. Measured against For what it's worth I re-ran the whole thing on The rebase will not be the last one. This is #254's mechanism exactly: a Happy to leave the cap question where it belongs, which is with the maintainers: it is +4 over two ceilings, and #322 has the measurement for judging whether that is the right price. |
2341055 to
82681be
Compare
|
Thank you for the detailed re-basing analysis — you were right on every number, and the branch is now regenerated exactly as you described. What changed in the latest push:
On the rebase-churn point: agreed, and this time the baseline bump is the final step — it was generated after the rebase onto 169ca89 rather than carried forward from the old base, so it reflects the tree as it stands. If another core merge lands before review, I'll regenerate again the same way rather than hand-adjust. |
82681be to
beb1333
Compare
beb1333 to
0180034
Compare
0180034 to
f44e589
Compare
751a570 to
2128c89
Compare
2128c89 to
f70f6a8
Compare
|
Updated for compatibility with #158 (keep Brahmic joiners U+200C/U+200D in The ASCII fast path here never touches the joiners (they are non-ASCII, so the Verified: ruff/format/ty clean, 64 store tests + signer + dupe-filter tests pass, full-codepoint sweep check 0 issues. |
2985158 to
99b4640
Compare
99b4640 to
1e8cdae
Compare
1e8cdae to
45f42a1
Compare
45f42a1 to
e91a062
Compare
|
Rewritten from scratch — the approach in the old body is gone, so reading this from the top is worth it. What was wrong with it. Two things, and the second is the serious one.
# tests/http/test_humans.py::test_invisible_characters_cannot_smuggle_instructions
"zero-width joiner": "a\u200db" -> assert clean_text(value) == "a b"Verified against three trees, same input: The old branch was carrying a security regression on behalf of an unmerged PR. Dropped. What replaces it. The It is also faster than the table was, because the win is skipping the walk rather than speeding it up: 81x on 4050-byte ASCII (2.1111 ms -> 0.0260 ms) vs the ~1.15x the table measured. Dirty input is unchanged, which is correct — it still has to be swept. Equivalence is re-verified against The soundness claim is now a test rather than a docstring assertion — adding |
|
Open pull requests citing the same issues:
If one already covers this change, review or build on it instead of racing it (CONTRIBUTING.md "Overlapping work"). |
46bb7a3 to
ade93ee
Compare
clean_text walked every character of every stored record to look for
invisibles, even though the overwhelming majority of records contain
none. Gate the walk behind str.isprintable(), which answers "is there
anything in here to sweep?" in C over the string's internal kind.
The gate is sound because every category in INVISIBLE_CATEGORIES is
non-printable by definition, so an isprintable() string cannot contain
one. Verified over all 1,114,112 codepoints: zero characters are both
swept and printable. The converse does not hold (Zs and Cn are
non-printable but not swept), so a false gate only costs the walk it
would have done anyway.
Output is unchanged for every input: 0 mismatches against the old
implementation over all codepoints and 40,000 random strings drawn from
C0, Cf, tag-block and surrogate pools.
ASCII 4050B 2.1111 ms -> 0.0260 ms 81x
ASCII 180B 0.1088 ms -> 0.0017 ms 66x
unicode clean 0.1571 ms -> 0.0025 ms 64x
dirty input unchanged (walk still runs)
core/store.py stays at 935 code lines, so no baseline change is needed.
Refs flop-labs#322
ade93ee to
2618589
Compare
luch91
left a comment
There was a problem hiding this comment.
Reviewed exact head 2618589. The str.isprintable() fast path is causally limited to inputs that cannot contain the swept Unicode categories; dirty inputs still execute the existing sweep. The added whole-codepoint invariant test pins that property, while the PR reports byte-equivalence over all Unicode codepoints and randomized pools, full tests, Ruff, formatting, and size checks clean. GitHub reports lint/tests/image, OpenAPI, and MCP worker-bundle checks successful. No blocker found.
|
Nit fold: tracked in #1004 instead of holding its own queue slot. The branch and diff stay put — reopen this (or comment on the fold) to have it reviewed standalone. |
What
Gate
clean_text's per-character sweep behindstr.isprintable().The walk itself is untouched. What changes is that it no longer runs for records
that have nothing to sweep, which is the overwhelming majority of them.
Why the gate is sound
Every category in
INVISIBLE_CATEGORIES(Cc Cf Cs Co Zl Zp) is non-printableby definition, so an
isprintable()string cannot contain a character thesweep would take. The converse does not hold —
ZsandCnare non-printablebut not swept — so a string that fails the gate merely pays for the walk it
would have done anyway. There is no input for which output changes.
That soundness is a property of the Unicode database, not of
store.py, so itis pinned by a test rather than a comment:
INVISIBLE_CATEGORIESgrowing toinclude a printable category (
Zs, say) fails the whole codepoint space atonce instead of silently letting invisibles through.
Verification
codepoint individually, plus 40,000 random strings drawn from ASCII, C0
controls,
Cf, theU+E0000tag block, surrogates and mixed pools —identical output and identical
StoreErrorraises.636 passed(the +1 is the codepoint test below).sz.py --check,ruff check,ruff format --checkclean.Numbers
Dirty input still walks, as it must. The win is that clean input stops paying
for the hazard it does not carry.
Size
core/store.pystays at 935 code lines — same as baseline.sz.py --checkpasses without touching
sz-baseline.json:Test
tests/unit/test_parse_properties.py::test_nothing_the_sweep_takes_can_pass_for_printable— asserts no codepoint is simultaneously in
INVISIBLE_CATEGORIESandprintable. RED confirmed by adding
"Zs"to the tuple:GREEN on the real tuple, and the existing sweep properties
(
test_clean_text_sweeps_trims_and_is_idempotent, the hostile-input HTTP test,the stateful model) pass unchanged.
Refs #322