Skip to content

perf: Lazy progress bar initialization in Levenshtein#109

Merged
ESultanik merged 1 commit into
masterfrom
perf/lazy-progress
Jun 3, 2026
Merged

perf: Lazy progress bar initialization in Levenshtein#109
ESultanik merged 1 commit into
masterfrom
perf/lazy-progress

Conversation

@ESultanik

Copy link
Copy Markdown
Collaborator

Summary

  • Avoid computing fringe_ranges dict when progress bar is disabled
  • Reduces overhead for programmatic use and quiet mode

Changes

In levenshtein.py, the dict comprehension for fringe_ranges was computed even when DEFAULT_PRINTER.quiet was True. Now defaults are set first, and computation only happens when the progress bar will actually be shown.

Before:

if DEFAULT_PRINTER.quiet:
    fringe_ranges = {}
    fringe_total = 0
else:
    fringe_ranges = { ... expensive computation ... }

After:

fringe_ranges = {}
fringe_total = 0
if not DEFAULT_PRINTER.quiet:
    fringe_ranges = { ... expensive computation ... }

Test plan

  • All 66 tests pass

🤖 Generated with Claude Code

Avoid computing fringe_ranges dict when progress bar will be disabled.
Previously, the dict comprehension was computed even when
DEFAULT_PRINTER.quiet was True, wasting cycles on unnecessary bounds()
calls and dict allocation.

Now defaults are set first, and computation only happens when the
progress bar will actually be shown.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@ESultanik ESultanik merged commit b9bf5b3 into master Jun 3, 2026
11 checks passed
@ESultanik ESultanik deleted the perf/lazy-progress branch June 3, 2026 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant