-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[red-knot] Eagerly normalize VendoredPathBuf
s
#11989
Conversation
|
I think my preferred solution here would be to improve the normalization logic to avoid allocating if the path's already normalized. But I'm not opposed to do the normalization eagerly. If we so the normalization eagerly, than I don't think the Path variant still makes sense, we should just use &PathBuf What's unclear to me is how the normalization works when joining paths because we would then have to normalize both paths before we can join them (which includes an allocation) |
Reading through this more, I'm leaning towards keeping it as is because it makes the API more cumbersome to use without very convincing benefits.
It's unclear to me if we actually do want to do this. I don't think there's anything wrong with
I agree that this is not ideal but I think we can instead change the normalization to return a I also expect that this won't be a very hot path because module resolution is cached. So we only resolve every module once. |
38a84d2
to
0775bc7
Compare
Yeah, I am also unsure. But I think part of the issue is that the current implementation on
Hmm, that's an interesting point. We could possibly have something like a |
CodSpeed Performance ReportMerging #11989 will improve performances by 4.92%Comparing Summary
Benchmarks breakdown
|
8d377c3
to
4bd1fe8
Compare
Leaving this for the time being |
Summary
Currently
VendoredPath
s are only normalized when you actually try to use them to lookup a path in the vendored zip archive. This has a couple of disadvantages:VendoredPath(Buf)
to begin with.String
. But this allocation is hidden from the user of theVendoredFileSystem
APIs, and feels somewhat wasteful if you're making several queries with the same path.This PR changes the design of the
VendoredFileSystem
,VendoredPath
andVendoredPathBuf
so that normalization is done eagerly at the point whenVendoredPath
andVendoredPathBuf
are created, rather than lazily when you try to use them to query paths in the zip archive. The main disadvantage of this is that it becomes a lot more annoying to construct aVendoredPath
from an&str
. Previously you could doVendoredPath::new("foo.pyi")
; now you must do&VendoredPathBuf::try_from("foo.pyi").unwrap()
.I'm not wedded to this PR as it does feel like it makes the API somewhat more awkward to use. But I said I'd look into this as a followup for #11863 (see e.g. #11863 (comment)). So this is the followup!
Test Plan
cargo test -p ruff_db