-
Notifications
You must be signed in to change notification settings - Fork 921
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
Make parking_lot
dependency optional
#650
Comments
Fixes rust-windowing#650 - parking_lot is now completely optional. TODO: parking_lot shouldn't be a dependency on Windows / Mac.
I don't think this is really necessary. The extra compile time |
The compilation time of a crate is not proportional to the number of its dependencies. |
I know about the theory that it shouldn't be slower, but that's not reality, sorry. The more dependencies, the slower the build time. I know it's "only" 3 seconds, but I have projects with more than 300 dependencies and each dependency takes "only" 3 seconds to compile. I have compile times of 10 - 20 minutes, if I can shave off 3 seconds - it's still something! And no, even after compilation the cost of these dependencies isn't free - cargos caching is far, far from perfect. Every time I switch between cargo check and cargo build it takes "only" 3 seconds more. Every time I switch between debug and release or from stable to nightly and back, "only" 3 seconds. When I build with LTO, it takes 15 seconds more because LTO is dog slow the more libraries you have. Every time I make a new build on travis or appveyor it takes "only" 10 seconds more because travis isn't very fast either. On every single commit. Every time I do cargo doc and cargo is too stupid to figure out that some dependencies are already checked and built it takes "only" 3 seconds more. And you forgot link time, every dependency adds to the time it takes to link all libraries together into one executable, which is especially slow because it's mostly single-threaded. Take your 3 seconds, multiply them by 300 and maybe you get why I'd like to cut down on dependencies. It's not like my entire application consists of just winit. I'm already trying to optimize all my other crates and cut down on unnecessary dependencies, but this is simply an easy opportunity to cut down on unnecessary dependencies. Right now I am looking through the Cargo.toml files of all projects I depend on looking for feature flags to disable. And every single dependency I can shave off is good and this would be a pretty easy opportunity. But alright - if you don't think it's necessary, close my PR and I'll just maintain a fork. |
If this is easy to implement and doesn't add much extra code to maintain, then this request makes sense to me. 👍 |
That's where I disagree. This makes the code more complex for almost nothing. |
@fschutt If you've got over 300 dependencies, I'd be mildly surprised if Also, I know this is addressing a fairly small part of your comment, but if you want to build docs for only your top-level crate you can do |
As a mere user of winit who don't know the internals well enough I can't really have a strong opinion on this. So I don't. I got curious though and took a look at the related PR and I think it can be rewritten in much smaller and fewer changes. Winit could use a |
@anderejd That is certainly a better option - my PR was more about proving that this "easy exchange" of I do get the argument that it's harder to read (which, as above, can be fixed), but I don't get the argument that winit can be sloppy with its dependencies just because other packages are sloppy too. I've already stripped out duplicates and no, parking_lot doesn't appear twice - for example there are lots of duplicates of So I think I'll see how much code it is to implement @anderejd s solution, so that less code changes are necessary and do a second PR and then we'll see if the idea is more feasible. |
For the record, the
Regarding this, I agree that In general, I'd tend to believe having few dependencies is a nice thing to have:
Regarding that, I agree that having Thus I believe the question is rather does winit actually need |
I was looking into compile time today and was surprised to find that winit was one of my biggest culprits. This surprised me because the crate appears to be a lightweight windowing only library. I guess this is the price to pay if you need to support multiple platforms. While searching to see if performance was actively being worked on I stumbled upon this issue. For me cold compile times are really important, and the argument that an incremental build is faster does not have any weight. What stood out to me however was the quote from #491 above.
This seems to be a flawed design philosophy to me. Moving away from the standard library should always be backed by a well founded reason. The fact that something uses less instructions and therefore is faster should not be enough to introduce a change like this. It should be backed by benchmarks proving it is faster, and those benchmarks needs to be real-world, not micro-benchmarks. In most cases, which mutex type used does not affect performance in any way because it is such a small part of the overall time spent. If it does affect performance, it is generally a sign that you are doing it wrong. Very often a mutex is the wrong choice in the first place if the contention is that high. With that said, most of the slow compile in my case came from wayland and after disabling that I gained 24 seconds (debug) which is great. Keep up the good work, I know how hard window handling can be |
It's ironic because It's correct that parking_lot is faster (rust-lang/rust#56410 (comment)), but winit doesn't use mutexes in the critical paths, only during startup and to manage resources correctly. I already did the PR to remove For build times, I now use a DLL, I compile every crate I need into a DLL and then dynamically load it. Makes recompilation + linking much faster. |
My comment is more about the principle, I did not do my research regarding this particular case. I have seen several PR's within the last year where projects change away from std to some other faster version on a hunch that it should be faster. I just wanted to make the point that the question should be "does it make things better", instead of "does it make things worse".
I have also noticed many people doing this and other hacks lately, and worry that this is a sign of sickness in the language. I worry things are taking a turn for the worse with clever people working around the problem instead of fixing the root cause which is the unnecessarily slow compilation. Anyway, I guess this is more of a philosophical question that I should have started on Rust Internals instead. |
Right now winit depends on
parking_lot
for Mutex handling - while I realize thatparking_lot
offers faster Mutex implementations than the standard library, it is also a pretty heavy dependency:This adds a lot of overhead to the compile time. winit is currently using
parking_lot
pretty much only for theMutex
, which can be exchanged with thestd::sync::Mutex
, so a simple feature flag should be possible so that crates depending on winit can turn off theparking_lot
mutex and use the standard library mutex - many crates don't need that extra performance and would rather go with better compile times.The text was updated successfully, but these errors were encountered: