|
1 | | -The assertion comparison helpers and the truncator now hand the |
2 | | -explanation between them as an iterator, so the dispatcher only has to |
3 | | -materialise lines the truncator actually keeps. For the typical small |
4 | | -diff this is a no-op; for the rare case where two large collections |
5 | | -fail to compare, peak memory drops by a few percent because the |
6 | | -millions of lines that would have been built and immediately discarded |
7 | | -are no longer built. |
| 1 | +Assertion explanations are now built lazily and the truncator stops |
| 2 | +the comparison helpers as soon as it has enough output, so comparing |
| 3 | +two large collections no longer builds the full diff in order to |
| 4 | +discard it. A focused micro-benchmark the worst case scenario |
| 5 | +(``set(range(500_000)) == set(range(1, 500_001))``) drops from ~2,200 ms |
| 6 | +to ~43 ms; but realistic test suite with mostly small diffs should be |
| 7 | +unchanged. |
8 | 8 |
|
9 | | -The truncation footer no longer reports the exact number of hidden |
10 | | -lines: ``...Full output truncated (N lines hidden), use '-vv' to |
11 | | -show`` is now ``...Full output truncated, use '-vv' to show``. |
12 | | -Dropping the count means the streaming truncator can return as soon |
13 | | -as it has reached the budget, without draining the rest of the |
14 | | -iterator just to count what it discarded. |
15 | | - |
16 | | -The "Full diff:" block for large iterables now passes each |
17 | | -``difflib.ndiff`` line through the syntax highlighter individually |
18 | | -instead of joining the full diff first. The streaming truncator can |
19 | | -stop ``difflib.ndiff`` as soon as its budget is filled. As a |
20 | | -side-effect, each diff line now starts with a redundant ``\x1b[0m`` |
21 | | -reset (invisible to the terminal). |
22 | | - |
23 | | -When the truncator is going to be active (``verbose < 2`` outside |
24 | | -CI), ``_compare_eq_iterable`` now caps ``PrettyPrinter`` output at |
25 | | -the truncator's ``truncation_limit_lines`` budget (plus 3 lines — |
26 | | -matching the truncator's own ``line_cap``: 2 lines for the truncation |
27 | | -message it appends + 1 for overshoot detection) via a budget-aware |
28 | | -stream that raises out of the formatter |
29 | | -once it has emitted enough lines. Combined with a fast path for |
30 | | -sorted set comparisons (try the natural ordering first, fall back to |
31 | | -the ``_safe_key`` wrap only on ``TypeError``), this turns the diff |
32 | | -for a 500,000-element set comparison from ~2,200 ms down to ~43 ms |
33 | | -(~50× speedup) while leaving the visible output identical for the |
34 | | -truncated display. ``-vv`` and CI runs still get the full uncapped |
35 | | -diff. |
| 9 | +The truncation footer no longer reports the hidden-line count |
| 10 | +(``...Full output truncated (N lines hidden), ...`` becomes |
| 11 | +``...Full output truncated, ...``); diff lines now carry a redundant |
| 12 | +``\x1b[0m`` reset prefix (invisible to terminals) so we can handle |
| 13 | +line one by one. |
0 commit comments