You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf: Importing nameparser takes about 47 ms #1552
import nameparser takes about 47 ms on my machine (3.2.1, Python 3.14). For a command-line tool that parses a few names, that's most of the run. I found three things that could help:
__init__.py imports _match, _suggest and config._order_names, which parse doesn't seem to use. Loading them on first access with a module __getattr__ would save about 13 ms.
_ARABIC_MARKS checks every code point from U+0600 to U+10F00, which takes 7 to 15 ms. Checking only the Arabic blocks finds the same marks on Unicode 16 and 17 in about 0.1 ms, and a test against the full scan would catch a new block.
Your benchmark counts calls per parse. Counting the modules and re.compile calls at import (26 and 58 now) would catch an import slowdown the same way.
The rest is spread over compiling regexes and loading modules, so I didn't find another easy win.
Best,
Simon
How I measured
All with nameparser 3.2.1. The machine was busy, so the times vary by about 20% between runs.
The 47 ms is time.perf_counter() around import nameparser on Python 3.14.4, over a few runs. The first parse() after it takes another 15 ms.
The 13 ms is the own time python -X importtime gives _match (7 ms), _suggest (4 ms) and config._order_names (3 ms).
The _ARABIC_MARKS line as written takes 7 ms on 3.14 and 15 ms on 3.15. Over these blocks it takes about 0.1 ms on both, and gives the same marks (Unicode 16 on 3.14, 17 on 3.15):
Activity