-
Notifications
You must be signed in to change notification settings - Fork 32
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
Enhancement to prevent cargo from recompiling allowlisted dependencies. #400
Comments
@anth0nyleung This is an interesting problem! The slight problem is that sometimes a crate has multiple features, like... oh... notorious crate Otherwise it is fairly eager to unify crate features, but this can cause other problems even if we don't hit compile errors, as enabling features can subtly change the behavior of a crate! I suppose we could have this as a configurable option? There are some allowlists for which following this proposal will Basically Always Be Okay. There are others which it would not be. We'd have to rely on the admin being thoughtful about that. |
That's interesting. The biggest problem im trying to avoid is re-building pgrx-pg-sys which is a very costly operation. It's very undesirable when this kind of unification problem happen because of say we support the serde crate that yields a different set of unified feature and at the end result in re-building pgrx-pg-sys. To make it worse, it takes quite some effort and time to find out what is causing the rebuild if it happens. I feel like there is a general lack of useful tools to debug this kind of issue. I think making it configurable makes sense since this falls into the bucket of a nice-to-have feature. We will also make it clear in the documentation that this does not guarantee to completely avoid such problem but in most cases it should work like you said. I can go ahead to start working on this if it sounds good. |
Hm. If the primary issue is pgrx-pg-sys, one of the things we can do is pay close attention to the features used by pgrx-pg-sys and its dependencies a bit more, so that it is more cagey about unifying them. I would be happy to review this feature but I would prefer a first-pass on the
|
@anth0nyleung Can you relate any examples on what features appearing in dependency sets are triggering pgrx-pg-sys rebuilds, specifically? |
@workingjubilee - sorry it took me a while to get back to you I think our goal is to avoid any dependencies rebuilds, not specifically to pgrx-pg-sys, but we would really like pgrx-pg-sys to not ever rebuild (unless we upgrade it to a new version) One example i can give is the When
However, plrust-trusted-pgrx also depends on getrandom, but the
In this case, suppose i have a function that was created without using rand. Now the fingerprint of getrandom does not have std. But when rand is used as dependencies in a new function, it'll case a rebuild on these dependencies
When this happens on a host with limited CPU, this can make a huge differences. We observed that a function can take close to 3 mins to compile when this rebuild happens, as opposed to just 5 seconds when there is no rebuild of crates. |
Hmm. I wonder how pgcentralfoundation/pgrx#1616 will affect the build times of PL/Rust functions. |
That looks like a pretty nice improvement. Looks like plrust 1.2.8 is still on pgrx 0.11.0. Can it work with 0.11.3 or develop branch of pgrx? I can try testing it. In the past my experience of compiling a PL/Rust function in the worst case is 45 hours... This is caused by pgrx-pg-sys, wondering how much improvement that change can bring |
Issue
We are facing the following problem today when using allowlisted dependencies.
We understand that all the dependency crates of pgrx (and those of the allowlisted crates) need to be compiled on cold start and that's a fixed cost. Suppose we have a fixed list of allowlisted crates, we want to prevent cargo from re-compiling any dependencies on consecutive build of plrust functions.
The way PL/Rust works today is that it adds crates into the Cargo.toml
[dependencies]
section based on what is specified in the[dependencies]
section of the function definition. I believe we could suffer from the feature unification problem in certain cases.For example, given crateA , crateB as allowlisted crates, and assume they both depends on crateC but crateA requires featureX in crateC and crateB requires featureY in crateC.
If we first create a function with just using crateA, the Rust fingerprint of crateC would say featureX is enabled. However, if we then create a function with just crateB, then the existing rlib for crateC cannot be re-used because now crateC needs to have featureY enabled which is not the case here. Similarly, if it is followed by creating a function which uses both crateA and crateB, the existing 2 version of rlib for crateC would not be compatible, and again needs to be recompiled because we need a crateC to to have both featureX and featureY enabled.
Proposal
The proposal i have is to use the same dependency set in Cargo.toml for every new function creates when allowlisted dependencies is a non-empty set.
E.g. Suppose the allowlist looks like this
When user request to create a function which uses dependencies with the above allowlist, plrust still checks if the requested dependencies are allowed. But when plrust creates the crate for it, we always use the same value for "dependencies" in Cargo.toml
I believe this is also how Rust playground manage to avoid rebuilding any dependencies with its top 100 crates that are supported by it.
The text was updated successfully, but these errors were encountered: