Repository navigation
👌 Make StateBase.src a plain attribute (~6% faster parsing) - #450
Open
deadstrobe5 wants to merge 3 commits into
Open
deadstrobe5 wants to merge 3 commits into
deadstrobe5 wants to merge 3 commits into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
StateBase.srcwas a property whose setter only reset the cache of the deprecatedsrcCharCode. Rules readstate.srcconstantly (~120k reads per render ofbenchmarking/samples/spec.md), so the property call alone was a measurable share of parse time.This makes
srca plain attribute. ThesrcCharCodecache is now a class-level(src, codes)pair, rebuilt wheneversrcis not the string it was built from. It is class-level becauseStateBlock,StateInlineandStateCoredon't callStateBase.__init__.Benchmark
pytest benchmarking/bench_core.py, Apple M5, Python 3.11, 3 runs each side:Interleaved A/B, 15 processes per side: median 61.1 → 57.0 ms (-6.7%), faster in 14 of 15 pairs.
Safety
commonmark,default,gfm-like,zeroandjs-defaultpresets.ruffandmypy --strictat the pre-commit pinned versions are clean.srcCharCodefollows reassignment ofsrc.Independent of #449 (different file); the two should stack.
Thanks for maintaining markdown-it-py!
Re-measured on CPython 3.14.7 (7 alternating processes per side, median): rendering benchmarking/samples/spec.md went from 26.6 ms to 25.3 ms (about 5%).