Skip to content

perf: Lazy progress bar initialization in Levenshtein#109

Open
ESultanik wants to merge 1 commit intomasterfrom
perf/lazy-progress
Open

perf: Lazy progress bar initialization in Levenshtein#109
ESultanik wants to merge 1 commit intomasterfrom
perf/lazy-progress

Conversation

@ESultanik
Copy link
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 <noreply@anthropic.com>
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