HRT's Python fork: Leveraging PEP 690 for faster imports

29 davidteather 16 8/8/2025, 4:12:03 PM hudsonrivertrading.com ↗

Comments (16)

nasretdinov · 6m ago
I wonder how much can be saved by using a local file system for imports though. In my testing just a mere presense of a home directory on NFS already dramatically slows down imports (by ~10x) due to Python searching for modules in home directory too by default.
roadside_picnic · 46m ago
Interviewed with HRT awhile back. While I didn't get past the final round, their Python internals interview (which I did pass) was an absolute blast to prepare for, and required a really deep dive into implementation specific details of CPython around things like exactly how collisions are handled in dict, details about memory management, etc. Pretty much had to spend a few weeks in the CPython source to prep, and was, for me, worth the interview just to really learn what's going on.

For most teams I would be pretty skeptical of a internal Python fork, but the Python devs at HRT really know their stuff.

nly · 7m ago
I interviewed with them as well. Something like 6-8 interviews only to be told they then, after that, were circulating my CV amongst teams and didn't have a fit for me...

But yes, like you I had a great experience

htrp · 9m ago
when milliseconds mean millions
fabioz · 1h ago
It'd have been really nice to have that PEP in as it'd have helped me not have to write local imports everywhere.

As it is, top-level imports IMHO are only meant to be used for modules required to be used in the startup, everything else should be a local import -- getting everyone convinced of that is the main issue though as it really goes against the regular coding of most Python modules (but the time saved to start up apps I work on does definitely make it worth it).

davidteather · 2h ago
The author interviewed me and talked about this project, so it was cool seeing a blog post posted about it
patrick91 · 30m ago
I really really want lazy imports in Python, it's would be a godsend for CLIs
rasjani · 2h ago
I know few modules that can take seconds to import but would have been nice to hear how much they actually gained?

Also maybe, if this approach could yield stats on if some import was needed or not ?

ecshafer · 1h ago
I thought HRT was a Cpp shop? Is Python used in their main business applications, or more for quants / data scientists?
almostgotcaught · 1h ago
every quant shop has QR and QT people that can barely write passable python let alone cpp - then the QD people have to integrate that stuff with prod cpp pipelines.
Spivak · 43m ago
> This process gets dramatically slower for … modules on distributed file systems, modules with slow side-effects

Oh no. Look I'm not saying you're holding it wrong, it's perfectly valid to host your modules on what is presumably NFS as well as having modules with side effects but what if you didn't.

I've been down this road with NFS (and SMB if it matters) and pain is the only thing that awaits you. It seems like they're feeling it. Storing what is spiritually executable code on shared storage was a never ending source of bugs and mysterious performance issues.

zzzeek · 1h ago
Gonna call this an antipattern. Do you need all those modules imported in every script ? Well then you save nothing on loadup time, the time will be spent regardless. Does every script not need those imports ? Well they shouldn't be importing those things and this small set of top level imports should be curated into a better, more fine grained list (and if you want to write tools, you can certainly identify these patterns using tooling similar to that which you wrote for LazyImports).
sunshowers · 1h ago
There are often large programs where not every invocation imports every module.

The lazy import approach was pioneered in Mercurial I believe, where it cut down startup times by 3x.

spicybright · 1h ago
For personal one file utility scripts, I'll sometimes only import a module on a code path that needs it. And make it global if the scope gets in the way.

It's dirty, but speeds things up vs putting all imports at the top.

rirze · 2h ago
Oh, it's a trading firm. That's why they can fund an internal fork of Python... That sounds nice...
globular-toast · 33m ago
Imagine if these guys put their intelligence towards improving the world.