|
| 1 | +# Custom Allocator for Toolchain |
| 2 | + |
| 3 | +* Proposal: [SE-0454](0454-memory-allocator.md) |
| 4 | +* Authors: [Saleem Abdulrasool](https://github.com/compnerd) |
| 5 | +* Review Manager: [Alastair Houghton](https://github.com/al45tair) |
| 6 | +* Status: **Awaiting Review** |
| 7 | +* Vision: N/A |
| 8 | +* Roadmap: N/A |
| 9 | +* Bug: N/A |
| 10 | +* Implementation: [swiftlang/swift#76563](https://github.com/swiftlang/swift/pull/76563) |
| 11 | +* Upcoming Feature Flag: N/A |
| 12 | +* Previous Proposal: N/A |
| 13 | +* Previous Revision: N/A |
| 14 | +* Review: N/A |
| 15 | + |
| 16 | +## Introduction |
| 17 | + |
| 18 | +The tools in the Swift toolchain require allocating data structures for |
| 19 | +compiling the code. Different memory allocators have differing performance |
| 20 | +characteristics. Changing the default memory allocator away from the default |
| 21 | +(system) allocator can yield benefits if the allocator is better tuned to the |
| 22 | +allocation patterns of the compiler. |
| 23 | + |
| 24 | +## Motivation |
| 25 | + |
| 26 | +A more effecient memory allocator would improve the performance of the compiler |
| 27 | +on Windows. This allows better developer productivity by reducing compile time. |
| 28 | + |
| 29 | +## Proposed solution |
| 30 | + |
| 31 | +We propose to adopt mimalloc as the memory allocator for the Swift toolchain on |
| 32 | +Windows. |
| 33 | + |
| 34 | +## Detailed design |
| 35 | + |
| 36 | +Building a test codebase yielded a 4% build time decrease when the toolchain was |
| 37 | +built with mimalloc. |
| 38 | + |
| 39 | +## Source compatibility |
| 40 | + |
| 41 | +This proposal does not affect source compatibility. |
| 42 | + |
| 43 | +## ABI compatibility |
| 44 | + |
| 45 | +This proposal does not affect ABI of code. |
| 46 | + |
| 47 | +## Implications on adoption |
| 48 | + |
| 49 | +Additional files will need to be built, packaged, and shipped as part of the |
| 50 | +toolchain. The mimalloc build is relatively light and the overall build time |
| 51 | +impact is minimal. |
| 52 | + |
| 53 | +This change has no implications for the runtime, only the toolchain is changed. |
| 54 | + |
| 55 | +## Future directions |
| 56 | + |
| 57 | +None at this time. |
| 58 | + |
| 59 | +## Alternatives considered |
| 60 | + |
| 61 | +Alternative memory allocators were considered, including |
| 62 | +[tcmalloc](https://github.com/google/tcmalloc) and |
| 63 | +[tbb](https://github.com/intel/tbb). mimalloc is well supported, developed by |
| 64 | +Microsoft, and has better characteristics comparatively. |
| 65 | + |
| 66 | +Leaving the allocator on the default system allocator leaves the compiler |
| 67 | +without the performance improvements of an alternative allocator. |
| 68 | + |
| 69 | +## Acknowledgements |
| 70 | + |
| 71 | +Special thanks to @hjyamauchi for performing the work to integrate the mimalloc |
| 72 | +build into the Windows build and collecting the performance numbers that showed |
| 73 | +the improvement. |
0 commit comments