Repository navigation
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.
normalizeran two regex substitutions on every input. The newline regex matched every"\n"and rebuilt the string, also when the input had no"\r". Nownormalizeruns the newline substitution only when the input contains"\r", and the regex matches only"\r\n?".str.replacenow replaces NULL characters, and only when the input contains one. The output does not change.Benchmark
Interleaved A/B, 20 to 30 rounds per side, Mann-Whitney test, Apple M5:
parseofbenchmarking/samples/spec.mdrenderofspec.mdrenderof one 10 KB paragraphparseofspec.mdwith CRLF line endingsI measured no slowdown on 31 benchmarks, including empty input, CR-only and NUL-heavy input, all presets,
renderer.renderandSyntaxTreeNode. A first version that used onlystr.replacewas 3.7% slower on PyPy for CRLF input, so this version keeps the regex for"\r".Safety
envand the syntax tree are identical on 1,003,726 inputs: the CommonMark spec, the port fixtures, the benchmark samples and random documents. I compared thecommonmark,default,gfm-like,zeroandjs-defaultpresets, and setups with typographer, breaks and mdit-py-plugins.pre-commit(ruff, ruff-format, mypy) is clean.test_normalizefor CRLF, CR, mixed line endings and NULL characters.