Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move distutils import into Language.build_library #168

Merged

Conversation

narpfel
Copy link
Contributor

@narpfel narpfel commented Oct 18, 2023

Importing distutils takes more than 90% of the total import time of tree_sitter, but it is only used when compiling new languages. The common case should not need to pay for that.

Some measurements:

Without this PR:

$ 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

With this PR:

$ python -Ximporttime -c "import tree_sitter" |& tail
import time:       214 |        214 |       _sha512
import time:       507 |       1625 |     random
import time:       309 |        309 |       _weakrefset
import time:       638 |        947 |     weakref
import time:       610 |       6328 |   tempfile
import time:       270 |        270 |     collections.abc
import time:       197 |        197 |     _typing
import time:      3145 |       3611 |   typing
import time:       404 |        404 |   tree_sitter.binding
import time:       702 |      16481 | tree_sitter

Importing `distutils` takes more than 90% of the total import time of
`tree_sitter`, but it is only used when compiling new languages. The
common case should not need to pay for that.
@amaanq amaanq merged commit 690bf56 into tree-sitter:master Nov 12, 2023
18 checks passed
@narpfel narpfel deleted the import-distutils-in-build_library branch November 12, 2023 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants