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)
- Miss distutils in Windows HOT 1
- Documentation is required.
- Is it possible to understand if an object is an instance of a certain class that may be defined in another file?
- How to use tree-sitter in Windows 10? HOT 6
- Special case not managed by the parser, when an expression is split without a backslash and the second line is dedented. HOT 4
- Example mismatch HOT 1
- Captures are not grouped HOT 3
- How to sync node after code edit? HOT 1
- README.md needs updates
- Tree-sitter Fails with Core Dump on Processing Large Input Code File HOT 4
- query failing in py-tree-sitter but compiling in tree-sitter playground HOT 1
- a __main__.py to build `vendor/tree-sitter-X` from command line HOT 1
- [bug] Cannot build a library in a directory containing two parsers. HOT 5
- The Python parser appears to be parsing comments and strings with unmatched parentheses as code HOT 2
- py-tree-sitter is 10x slower than lezer-parser HOT 9
- FileNotFoundError: [Errno 2] No such file or directory: 'tree-sitter-java/src/parser.c' HOT 2
- UTF-16 encoding support is wanted HOT 1
- Can't install tree-sitter-python HOT 1
- [tree-sitter-python] `No matching distribution found for tree-sitter-python` HOT 1
- Broken (?) README instructions to pip install pre-compiled binary wheels HOT 1
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.