Skip to content

Conversation

@ESultanik
Copy link
Collaborator

Summary

  • Move PIL imports from module-level to function-level in nes.py and jpeg.py
  • PIL is now only loaded when actually parsing NES ROMs or JPEG2000 images
  • Most files analyzed by PolyFile don't require PIL, so this defers the ~2s PIL import to when it's actually needed

Performance Results

Metric Before After Improvement
Import time 4246ms 358ms 92% faster

Test plan

  • Run pytest tests/test_magic.py tests/test_pdf.py - same test results as baseline
  • Verify PIL is not loaded after import polyfile
  • Verify PIL is loaded on-demand when parsing NES/JPEG2000 files

🤖 Generated with Claude Code

@ESultanik ESultanik force-pushed the perf/lazy-pil-import branch 2 times, most recently from 800b0d4 to b0ac558 Compare January 20, 2026 22:02
Move PIL imports from module-level to function-level, so PIL is only
loaded when actually parsing NES ROMs (nes.py) or JPEG2000 images
(jpeg.py). Most files analyzed by PolyFile don't require PIL.

Performance improvement:
- Import time: 4246ms → 358ms (92% faster)

The PIL library takes ~2s to import due to loading many image codec
modules. Deferring this import until needed dramatically reduces
startup time for the common case.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@ESultanik ESultanik force-pushed the perf/lazy-pil-import branch from b0ac558 to 9d6c04d Compare January 20, 2026 22:15
@ESultanik ESultanik merged commit f6e1361 into master Jan 20, 2026
10 checks passed
@ESultanik ESultanik deleted the perf/lazy-pil-import branch January 20, 2026 22:21
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.

2 participants