Comments (3)
Something's off in your system, same code for me:
It took 0.0004069805145263672 seconds to import tree_sitter
Are you on Linux? Can you use perf to profile it and upolad the data here?
from py-tree-sitter.
There’s also python -Ximporttime
to profile import times (or importtime-waterfall
to get a graphical output), for me importing tree_sitter
takes 140 ms, 130ms of which are spent in importing distutils
:
$ python -Ximporttime -c 'import tree_sitter'
import time: self [us] | cumulative | imported package
[...]
import time: 613 | 613 | json.encoder
import time: 347 | 2441 | json
import time: 2406 | 129771 | distutils
import time: 513 | 130284 | distutils.ccompiler
import time: 444 | 444 | shlex
import time: 176 | 176 | distutils.py39compat
import time: 168 | 168 | distutils._functools
import time: 927 | 1269 | distutils.sysconfig
import time: 168 | 168 | distutils._macos_compat
import time: 361 | 2240 | distutils.unixccompiler
import time: 653 | 653 | tree_sitter.binding
import time: 871 | 140812 | tree_sitter
Unrelated to this issue, I think it’s probably worthwhile to move the distutils
import into Language.build_library
to only pay for the import when it’s actually needed.
from py-tree-sitter.
Nice! I didn't know about importtime. I'm running this on linux (SLES12). I did some further debugging. It turns out that I had my PYTHONPATH set to point directly to the site packages (which are on NFS), however the tree_sitter module was only installed in my venv (also on NFS). That was the only module that was in my local venv and not in site packages which is why I did not see a similar time penalty for any of the other modules I'm using. Python was still able to find tree_sitter, but I guess using PYTHONPATH caused a huge time penalty.
Here is the import time with the bad PYTHONPATH:
[...]
import time: 419 | 419 | json.encoder
import time: 296 | 1698 | json
import time: 2723 | 827802 | distutils
import time: 1107 | 828909 | distutils.ccompiler
import time: 314 | 314 | shlex
import time: 808 | 808 | distutils.py39compat
import time: 665 | 665 | distutils._functools
import time: 1197 | 2670 | distutils.sysconfig
import time: 730 | 730 | distutils._macos_compat
import time: 1078 | 4792 | distutils.unixccompiler
import time: 932 | 932 | tree_sitter.binding
import time: 1825 | 840382 | tree_sitter`
Here it is without PYTHONPATH being set:
[...]
import time: 373 | 373 | json.encoder
import time: 258 | 1510 | json
import time: 4514 | 157710 | distutils
import time: 1198 | 158908 | distutils.ccompiler
import time: 315 | 315 | shlex
import time: 931 | 931 | distutils.py39compat
import time: 804 | 804 | distutils._functools
import time: 1400 | 3133 | distutils.sysconfig
import time: 827 | 827 | distutils._macos_compat
import time: 1528 | 5801 | distutils.unixccompiler
import time: 1314 | 1314 | tree_sitter.binding
import time: 4009 | 173965 | tree_sitter
from py-tree-sitter.
Related Issues (20)
- Remove/replace the usage of distutils HOT 1
- Missing aarch64 packages for 0.21.x HOT 1
- Make the Node class hashable. HOT 1
- [tree-sitter-python] No matching distribution found for tree-sitter-python HOT 3
- Python nil pointer crash while iterating over query captures
- Results returned by `Query.matches()` and `Query.captures()` are different HOT 2
- FutureWarning: Language(path, name) is deprecated. HOT 1
- Deprecation warning `Language.build_library is deprecated. Use the new bindings instead` HOT 4
- Tree sitter gets stuck HOT 3
- Can't pip install tree-sitter-python on mac os with apple silicon HOT 1
- way to get parser for typescript/tsx HOT 2
- How to get the location of a variable name in the whole function?
- Does that mean it's a conversion error? HOT 2
- How to build 0.22.x from source HOT 1
- TypeError on initializing Language with tree_sitter_python after following example code in readme. HOT 2
- Replacement of `build_library`
- Fails to load language on 32 bit HOT 6
- Post Source to pypi HOT 1
- cannot install the tree-sitter-python using pip HOT 1
- How to audit binary wheels?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from py-tree-sitter.