Skip to content

Lazy import (after #11)#12

Open
paugier wants to merge 2 commits intowillynilly:mainfrom
paugier:lazy-import
Open

Lazy import (after #11)#12
paugier wants to merge 2 commits intowillynilly:mainfrom
paugier:lazy-import

Conversation

@paugier
Copy link

@paugier paugier commented Jan 7, 2026

I tried again lazy import (#8) after #11:

For this branch (lazy import):

$ time python -c "import rfc3987_syntax"
real	0m0,023s
$ time python -c "import rfc3987_syntax as m; m.syntax_parser"
real	0m0,088s

To be compared with, for agentydragon:adgn/one-parser

$ time python -c "import rfc3987_syntax"
real	0m0,088s
$ time python -c "import rfc3987_syntax as m; m.syntax_parser"
real	0m0,088s

and for main:

$ time python -c "import rfc3987_syntax"
real	0m0,650s
$ time python -c "import rfc3987_syntax as m; m.syntax_parser"
real	0m0,654s

agentydragon and others added 2 commits December 29, 2025 05:36
Previously, make_syntax_validator() created a new Lark parser for each
rule, which was expensive (~660ms total import time). This change:

- Defines ALL_START_RULES containing all grammar rules needed by validators
- Creates a single shared syntax_parser with all start rules upfront
- Refactors make_syntax_validator() to use functools.partial with
  is_valid_syntax() instead of creating new parsers

Import time reduced from ~660ms to ~72ms (9x speedup).

Testing protocol:
- Created timing script that clears module cache and measures import time
- Ran 5 iterations for each version to account for variance
- Used git stash to preserve dirty state while testing HEAD
- Results: HEAD averaged ~662ms, this change averages ~72ms
- All existing tests pass (2/2)
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