microsoft / terminal

The new Windows Terminal and the original Windows console host, all in the same place!
MIT License
94.96k stars 8.22k forks source link

Add and use snmalloc, mimalloc for allocation performance #10976

Open WSLUser opened 3 years ago

WSLUser commented 3 years ago

Description of the new feature/enhancement

Github randomly revealed a project from Microsoft that upon investigation seems like it would be pretty useful here to possibly boost performance for allocations. https://github.com/microsoft/snmalloc

Proposed technical implementation details (optional)

WSLUser commented 3 years ago

https://github.com/microsoft/mimalloc is more general purpose while snmalloc is for message-passing specifically. Use both as needed in places where allocations need to occur and can't simply be removed.

WSLUser commented 3 years ago

So it looks all we need to do here is add it to the build steps. https://github.com/contour-terminal/contour/pull/341/ shows how it's done for cmake. MSVC makes it bit more difficult as you need to ensure build steps are done properly in order and while I'd like to take a stab at this, I'm concerned about messing the build up trying to add this. I'd start with mimalloc first in this case and follow all of it's recommendations for flags for C++:

For best performance in C++ programs, it is also recommended to override the global new and delete operators. For convience, mimalloc provides mimalloc-new-delete.h which does this for you -- just include it in a single(!) source file in your project. In C++, mimalloc also provides the mi_stl_allocator struct which implements the std::allocator interface.

Also see https://github.com/microsoft/mimalloc#override-on-windows for Windows specific optimizing.

WSLUser commented 3 years ago

@skyline75489 Are you comfortable with messing with the build steps to see how much of a boost we get in Process Explorer?

lhecker commented 3 years ago

Chester is unfortunately currently already preoccupied. Since the benefits in Contour were rather significant I'll look into this in his stead.