在 Twitter 上看到一則 "The Horror in the Standard Library" 這麼聳動的標題,不改好奇的個性,當然要讀他到底在說些什麼?摘錄文章幾個要點:
從這篇文章提到一些 Library 或者軟體,整理如下:
- We tried valgrind, dmalloc, the Microsoft Visual Studio memory profiler (yes we tried running it in Windows via an elaborate shim just to use this), and glibc's built-in memory tracing. Nothing worked. It's leaking but it's not. It's leaking but the debugger says no memory was lost.
- The default allocator in the standard C library is designed for an acceptable trade-off between memory use and performance under ordinary work loads, but it doesn't always perform ideally in aggressively multithreaded or very high throughput applications. Luckily there are very highly regarded drop-in replacements like jemalloc. Trembling with anticipation that maybe... just maybe... I'd found the answer... I dropped in jemalloc and ran the test.
- We now have code in production (in ZeroTier Central) that force disables libstdc++ allocation pools via the above environment variable and ensures that jemalloc is preloaded.We use RethinkDB and it's also written in C++, so I decided to take a look and see if setting the same environment variable and preloading jemalloc might improve our database performance.Looks like they discovered this problem too.
- GNU libstdc++ is broken. This is pretty unforgiveable. How many other C++ developers on Linux are banging their heads on the table right now as they search in futility for memory leaks that do not exist?
- The right answer to "malloc is slow" is to make it faster. This way regular C programs and programs written in other languages can also benefit. Adding wheels to the wheel is sometimes forgiveable when dealing with closed systems that you can't fix but libstdc++ and glibc are both open source GNU projects. The jemalloc allocator works very well so why not ship that or something very much like it?
從這篇文章提到一些 Library 或者軟體,整理如下:
- jemalloc is a general purpose malloc(3) implementation that emphasizes fragmentation avoidance and scalable concurrency support.
- JSON for Modern C++
- RethinkDB :The open-source database for the realtime web
- Twisted is an event-driven networking engine written in Python and licensed under the open source
- Twisted Introduction 是一本介紹 Twisted 的書
留言
張貼留言