TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Recording and visualising the 20k system calls it takes to "import seaborn"

111 pointsby sYnfoover 1 year ago

7 comments

nsmover 1 year ago
Related to this, if you set the env var `PYTHONPROFILEIMPORTTIME=1` or run python with `-X importtime`, it will print out the cumulative and self times to import various modules.<p>There is then this neat tool to visualize the data. <a href="https:&#x2F;&#x2F;kmichel.github.io&#x2F;python-importtime-graph&#x2F;" rel="nofollow">https:&#x2F;&#x2F;kmichel.github.io&#x2F;python-importtime-graph&#x2F;</a><p>Highly recommend to find the worst imports affecting your program startup time.<p>In general, the python community values tend towards functionality over performance. For example, large modules (looking at networkx here) will often import a bunch of there submodules in their __init__.py, which means all modules now end up loaded even if you didn&#x27;t need them.<p>I&#x27;ve never tried <a href="https:&#x2F;&#x2F;pyoxidizer.readthedocs.io&#x2F;en&#x2F;stable&#x2F;oxidized_importer.html" rel="nofollow">https:&#x2F;&#x2F;pyoxidizer.readthedocs.io&#x2F;en&#x2F;stable&#x2F;oxidized_importe...</a>, but it compiles all the imports into one, memory mapped file, that _may_ speed up the importing.<p>Having everything compiled to bytecode also helps a bunch.
评论 #39411500 未加载
dmwilcoxover 1 year ago
I&#x27;ve been writing python for going on 20 years now and while it was a good language to cut my teeth on thus sort of analysis brings only horror. Many thanks to the author for dropping into plain view.<p>I&#x27;m going to go back to learning more C and Forth... And shake my fist at passing clouds :)
评论 #39404825 未加载
评论 #39404153 未加载
评论 #39403630 未加载
评论 #39403783 未加载
评论 #39404603 未加载
shadycuzover 1 year ago
I also wrote a somewhat similar tool. I call it deep-ast. It&#x27;s pretty flexible in what it can track. I used it when refactoring some code in urllib3, to see what Exceptions could get raised along a given code path.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;DontShaveTheYak&#x2F;deep-ast">https:&#x2F;&#x2F;github.com&#x2F;DontShaveTheYak&#x2F;deep-ast</a>
albertgoeswoofover 1 year ago
Today I asked a devops engineer to tell me how much time a long (3 seconds avg) api call was spending on database queries, application logic, and network etc. He couldn’t understand the request and instead opened up the azure console and recommended we increase the number cpu cores &#x2F; memory if performance is an issue.<p>I look at posts like this and cry.
评论 #39404168 未加载
评论 #39404177 未加载
评论 #39404769 未加载
评论 #39409109 未加载
ok123456over 1 year ago
If it&#x27;s a large project, I&#x27;ll use local imports to defer this cost only around where I&#x27;m plotting. That way, if I have another entry point that only does computation or is part of a larger system like a web application, it won&#x27;t have this sort of overhead.
rldjbpinover 1 year ago
<a href="https:&#x2F;&#x2F;archive.is&#x2F;XVWSO" rel="nofollow">https:&#x2F;&#x2F;archive.is&#x2F;XVWSO</a><p>Aggressive anti-adblock plugin used.
mrnonchalantover 1 year ago
Very cool! I liked the instruction counting article as well.