Skip to content

Conversation

@ESultanik
Copy link
Collaborator

Summary

  • Make Kaitai struct parsers lazy-loaded by deferring KaitaiParser.load() until first use
  • Remove unused imports (Gif, Jpeg, Png) that were imported at module level but never used
  • Previously all 31 Kaitai parsers were loaded at import time; now they load on-demand

Implementation

  • Add LazyKaitaiParser class that wraps the actual parser loading
  • Parser is registered immediately but KaitaiParser.load() is deferred until __call__
  • Remove dead code: from .kaitai.parsers.gif import Gif etc. were unused

Performance Results

When combined with other lazy loading optimizations, Kaitai parsers no longer contribute to import time overhead. Parsers for rarely-used formats (RPM, XAR, DOOM, etc.) are only loaded when matching those file types.

Test plan

  • Run pytest tests/test_magic.py tests/test_kaitai.py - same test results as baseline
  • Verify Kaitai parsers are loaded on-demand when matching files

🤖 Generated with Claude Code

@ESultanik ESultanik force-pushed the perf/lazy-kaitai branch 2 times, most recently from 41e74cc to 61aa87e Compare January 20, 2026 22:02
Make Kaitai struct parsers lazy-loaded by deferring the
KaitaiParser.load() call until the parser is first invoked. Previously,
all 31 Kaitai parsers were loaded at import time even if the file type
was never encountered.

Also removes unused imports (Gif, Jpeg, Png) that were imported at
module level but never used.

Changes:
- Add LazyKaitaiParser class that wraps parser loading
- Remove unused Gif, Jpeg, Png imports from kaitaimatcher.py
- Parsers are now loaded on-demand when first parsing a matching file

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@ESultanik ESultanik merged commit 91cc253 into master Jan 20, 2026
10 checks passed
@ESultanik ESultanik deleted the perf/lazy-kaitai branch January 20, 2026 22: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.

2 participants