Fast path for FileRegressionFixture.check when contents already match#241
Open
adamtheturtle wants to merge 1 commit intoESSS:masterfrom
Open
Fast path for FileRegressionFixture.check when contents already match#241adamtheturtle wants to merge 1 commit intoESSS:masterfrom
FileRegressionFixture.check when contents already match#241adamtheturtle wants to merge 1 commit intoESSS:masterfrom
Conversation
Short-circuit the pass path with a byte-exact in-memory comparison so the .obtained file, file re-reads, and difflib machinery are only triggered on a real mismatch. Behaviour is preserved for mismatches, custom check_fn, --force-regen, and --regen-all.
nicoddemus
requested changes
Apr 23, 2026
Member
nicoddemus
left a comment
There was a problem hiding this comment.
Thanks @adamtheturtle for the contribution. Please take a look at my comment. 👍
| the basename. | ||
| :param obtained_filename: complete path to use to write the obtained file. By | ||
| default will prepend `.obtained` before the file extension. | ||
| :param fast_equal_fn: Optional function receiving the expected file path and returning |
Member
There was a problem hiding this comment.
Do we really need this extra complexity?
Seems like the short-circuit could just convert the input into bytes, and compare directly with the written file (as bytes).
This is an optimization: if for some reason the user has changed the line ending or the encoding, then the short circuit will fail, and fallback to the standard path of doing the full comparison.
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.
Closes #240.
Summary
FileRegressionFixture.checkso the pass path avoids writing a.obtainedfile, re-reading both files, and constructingdifflib.HtmlDiffmachinery.fast_equal_fnparameter onperform_regression_check; no other fixtures change behaviour.--force-regen/--regen-allis set, when the user supplies a customcheck_fn, or when the expected file does not yet exist. Mismatches fall through to the existing code path unchanged.Timings
Measured against
masterwith a 200-line text golden, 1000 iterations per run, macOS / Python 3.13.9:checkOn the mismatch path the fast path adds one
read_bytes()+ oneencode()before falling through — within noise of the ~800 us the existing mismatch branch already spends on the.obtainedwrite and HTML diff.Tests
test_skips_obtained_write_on_matchand_binary— fast path does not write.obtainedwhen contents match.test_writes_obtained_on_mismatch— mismatch still writes.obtainedand raisesFILES DIFFER.test_custom_check_fn_disables_fast_path— user-suppliedcheck_fnalways receives an obtained file.Happy to adjust API shape / docs / CHANGELOG wording as needed.