Improve responsiveness when invoked via Python#9315
Merged
charliermarsh merged 2 commits intoastral-sh:mainfrom Dec 31, 2023
Merged
Improve responsiveness when invoked via Python#9315charliermarsh merged 2 commits intoastral-sh:mainfrom
charliermarsh merged 2 commits intoastral-sh:mainfrom
Conversation
ofek
commented
Dec 29, 2023
Member
|
Hey :) Can you show the performance changes for invoking Ruff itself rather than microbenchmarks of the import? It's hard to tell if these changes are worthwhile in our use-case. I generally prefer the readability of undeferred imports and use of |
Contributor
Author
I can't easily test right now in Docker, these are on my Windows machine. |
Contributor
|
charliermarsh
approved these changes
Dec 29, 2023
Member
charliermarsh
left a comment
There was a problem hiding this comment.
This seems reasonable to me.
Closed
meta-codesync bot
pushed a commit
to facebook/dotslash
that referenced
this pull request
Oct 31, 2025
Summary: Hello again! This is the second [half](#82) of what we require in order to start using DotSlash. This moves over the [code](https://github.com/ofek/dotslash-python) for the `dotslash` Python [package](https://pypi.org/project/dotslash/) I created over the weekend. The ownership transfer on PyPI is in progress. The package serves a similar purpose to the existing `fb-dotslash` Node.js [package](https://www.npmjs.com/package/fb-dotslash) stored in the top level [`node`](https://github.com/facebook/dotslash/tree/main/node) directory. Some notes: - Python 3.9 is EOL at the end of the month so I chose to require 3.10+. - The package exposes a single `locate` function for finding the path to the binary that was installed by the installation. The logic was adapted from equivalents like UV's [finder](https://github.com/astral-sh/uv/blob/141369ce73b7b0b4e005b0f45107d13c828a99e0/python/uv/_find_uv.py). I optimized the path resolution to perform as little work as necessary and to do so lazily. ``` ❯ docker run --rm -it python:3.14 bash root@8a442038a1c8:/# curl -fsSL https://github.com/sharkdp/hyperfine/releases/download/v1.19.0/hyperfine-v1.19.0-x86_64-unknown-linux-musl.tar.gz \ | tar -xzO 'hyperfine-v1.19.0-x86_64-unknown-linux-musl/hyperfine' \ | install -m 0755 /dev/stdin /usr/local/bin/hyperfine root@8a442038a1c8:/# pip install -qqq dotslash uv root@8a442038a1c8:/# hyperfine -m 100 --warmup 10 "python -m timeit -n 1 -r 1 -s 'from uv import find_uv_bin' 'find_uv_bin()'" Benchmark 1: python -m timeit -n 1 -r 1 -s 'from uv import find_uv_bin' 'find_uv_bin()' Time (mean ± σ): 33.6 ms ± 2.4 ms [User: 25.3 ms, System: 7.6 ms] Range (min … max): 30.3 ms … 46.1 ms 100 runs root@8a442038a1c8:/# hyperfine -m 100 --warmup 10 "python -m timeit -n 1 -r 1 -s 'from dotslash import locate' 'locate()'" Benchmark 1: python -m timeit -n 1 -r 1 -s 'from dotslash import locate' 'locate()' Time (mean ± σ): 23.5 ms ± 1.0 ms [User: 17.8 ms, System: 5.7 ms] Range (min … max): 22.1 ms … 26.9 ms 127 runs root@8a442038a1c8:/# # Show time it takes to locate binaries root@8a442038a1c8:/# python -m timeit -n 1 -r 1 -s "from uv import find_uv_bin" "find_uv_bin()" 1 loop, best of 1: 7.71 msec per loop root@8a442038a1c8:/# # This includes the time of all imports (still faster) root@8a442038a1c8:/# python -m timeit -n 1 -r 1 -s "from dotslash import locate" "locate()" 1 loop, best of 1: 2.86 msec per loop root@8a442038a1c8:/# # This excludes import times to match eager behavior of UV root@8a442038a1c8:/# python -m timeit -n 1 -r 1 -s "from dotslash import locate,_locate" "locate()" 1 loop, best of 1: 1.14 msec per loop ``` - The shipped binary can be invoked directly with `python -m dotslash`. If there ever is a desire to represent paths as anything other than strings in the implementation, please [don't](astral-sh/ruff#9315). - Builds require setting the `DOTSLASH_VERSION` environment variable to the desired release tag of DotSlash (the `v` is optional). This will be used as the package version and, by default, for fetching the appropriate release artifact. - Rather than making HTTP requests during builds, you can set the `DOTSLASH_SOURCE` environment variable to the path to a directory containing the release artifacts. I strongly recommend that the release process uses that eventually (and the Node.js package's [build script](https://github.com/facebook/dotslash/blob/646102b468bb5e820e45d3d06a7ee63e13b51d66/node/scripts/build-package.js) gains support). - I remove build instructions from the content of the PyPI project's landing page since the information wouldn't be useful for users. - I moved the release jobs of the downstream packages into a separate workflow that only executes when called by the primary release workflow. I already configured Trusted Publishing on PyPI to use the `release-downstream.yml` workflow from this repository. You might find hazy details about their support for reusable workflows but [this comment](pypi/warehouse#11096 (comment)) provides the full picture. Basically, the claim they chose happens to work for the most nested called workflow when using reusable workflows but not the top level one. Whenever support for that happens there will be no user impact for existing supported scenarios. --- cc sdwilsh bigfootjon for review as requested Also, it's worth noting that PyPI was blocking the name `dotslash` due to certain [rules](https://github.com/pypi/warehouse/blob/main/warehouse/migrations/versions/d18d443f89f0_ultranormalize_name_function.py) and di very graciously provided the override 🙇♂️ Pull Request resolved: #87 Test Plan: CI Reviewed By: bigfootjon Differential Revision: D84891338 Pulled By: sdwilsh fbshipit-source-id: 493086f3a0106d0c0e83c88eeb82bfe9ba277507
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This saves a handful of milliseconds on Windows and even more on other platforms when running
python -m ruff. On non-Windows systems the process is replaced directly (impossible on Windows unfortunately).