-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Internalize BevyManifest logic. Switch to RwLock #18263
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
Conversation
|
Its kind of scary that a crate dep was added that easily. I dont think it was malicious here but it shows this is a very possible attack vector. Sneak an official-sounding crate you made into macro path, then do a patch release that gets automatically picked up by cargo which has the macros insert malicious code invisibly. |
|
My thoughts exactly. Dependencies should be a "last resort" sort of thing, and when we take them, they should be in a trusted (known actor / high traffic / high visibility / high review) context. |
|
I have removed the bevy crate remapping test as it is no longer supported in this impl. I did write code to re-add support, but supporting that means scanning and string comparing every dependency (and every dev dependency) on all macro executions that don't match the |
# Objective When reviewing #18263, I noticed that `BevyManifest` internally stores a `DocumentMut`, a mutable TOML document, instead of an `ImDocument`, an immutable one. The process of creating a `DocumentMut` first involves creating a `ImDocument` and then cloning all the referenced spans of text into their own allocations (internally referred to as `despan` in `toml_edit`). As such, using a `DocumentMut` without mutation is strictly additional overhead. In addition, I noticed that the filesystem operations associated with reading a manifest and parsing it were written to be completed _while_ a write-lock was held on `MANIFESTS`. This likely doesn't translate into a performance or deadlock issue as the manifest files are generally small and can be read quickly, but it is generally considered a bad practice. ## Solution - Switched to `ImDocument<Box<str>>` instead of `DocumentMut` - Re-ordered operations in `BevyManifest::shared` to minimise time spent holding open the write-lock on `MANIFESTS` ## Testing - CI --- ## Notes I wasn't able to measure a meaningful performance difference with this PR, so this is purely a code quality change and not one for performance. --------- Co-authored-by: Carter Anderson <[email protected]>
Objective
Fixes #18103
#17330 introduced a significant compile time performance regression (affects normal builds, clippy, and Rust Analyzer). While it did fix the type-resolution bug (and the general approach there is still our best known solution to the problem that doesn't involve significant maintenance overhead), the changes had a couple of issues:
Solution
Mutex<BTreeMap<PathBuf, &'static Mutex<CargoManifest>>>forRwLock<BTreeMap<PathBuf, CargoManifest>>. Note that I used theparking_lotRwLock because it has a mapping API that enables us to return mapped guards.