matklad / once_cell

Rust library for single assignment cells and lazy statics without macros
Apache License 2.0
1.87k stars 109 forks source link

Improve `imp_pl` size #140

Closed quininer closed 3 years ago

quininer commented 3 years ago

I have observed that the program size has increased a lot after enabling the parking_lot feature.

parking_lot will actively inline methods, which leads to some unnecessary duplication of code. see https://github.com/Amanieu/parking_lot/pull/236

This PR introduces an InlineLessRawMutex wrapper to avoid this problem. initialize is a cold path, I don't think this will cause performance problems.

matklad commented 3 years ago

I think if the goal here is solely to reduce code size due to PL, than the problem should be either solved upstream, or worked-around downstream. Placing a workaround into an intermediate library isnt’ worth it, imo :P

Curious, would slappping inline(never) onto initialize help?

We might also want to ditch pl mutexes altogether, and use the underlying parking mechanism directly. That should also reduce the size of cell itself, I think. I’d be willing to accept/write a patch for that, but it should be written in a very clean style, such that it’s easy to see that it is correct.

quininer commented 3 years ago

The parking_lot cannot determine whether this is a cold path, so putting this method upstream is not appropriate.

Curious, would slappping inline(never) onto initialize help?

This won't help, because initialize is a generic method.

matklad commented 3 years ago

This won't help, because initialize is a generic method.

Ag, that is a bug I think! Take a look at the std impl for the trick to un-generalize it.

quininer commented 3 years ago

I added initialize_inner according to imp_std.

matklad commented 3 years ago

bors r+

Thanks!

bors[bot] commented 3 years ago

Build succeeded: