3 ms·
I've had much grief with this in Rust, adding to an array with "push". Down at the bottom, this grows by resizing an allocation. Ordinarily, that's cheap. But
by Animats 3y ago
I've had much grief with this in Rust, adding to an array with "push".
Down at the bottom, this grows by resizing an allocation. Ordinarily, that's cheap. But if you're resizing a reasonably sized array, at least under Wine it's a copy of the array with the lock on the memory allocator set. There's a spinlock involved. If many threads are allocating, futex congestion is possible and speed drops by two orders of magnitude. Ouch.
- nynx 3y agoThat’s a bug in the allocator. Realloc should not grab a lock the entire time.
- Animats 3y agoIt's complicated. There are three nested locks. I could see snapshots of what was happening in gdb, but don't fully understand the dynamics. The effect was that a game-type program dropped from 60FPS to 0.5 FPS.
- hawk_ 3y agoSurely that must be a specific allocator. Does rust allow you to use say jemalloc or alternatives? Or are you saying this lock is acquired no matter which allocator is used?
- connicpu 3y agoYeah you can override the global allocator pretty easily[1]. But the default uses the system allocator, and I guess it sounds like Wine's is pretty bad [1]: https://doc.rust-lang.org/std/alloc/index.html#the-global_allocator-attribute https://doc.rust-lang.org/std/alloc/index.html#the-global_al...
- Animats 3y agoIt's in the DLL that Wine uses to emulate Windows. Not in the Rust library. Bug report: [1] [1] https://bugs.winehq.org/show_bug.cgi?id=54979 https://bugs.winehq.org/show_bug.cgi?id=54979