cosmopolitan/third_party
Justine Tunney 3609f65de3
Make malloc() go 200x faster
If pthread_create() is linked into the binary, then the cosmo runtime
will create an independent dlmalloc arena for each core. Whenever the
malloc() function is used it will index `g_heaps[sched_getcpu() / 2]`
to find the arena with the greatest hyperthread / numa locality. This
may be configured via an environment variable. For example if you say
`export COSMOPOLITAN_HEAP_COUNT=1` then you can restore the old ways.
Your process may be configured to have anywhere between 1 - 128 heaps

We need this revision because it makes multithreaded C++ applications
faster. For example, an HTTP server I'm working on that makes extreme
use of the STL went from 16k to 2000k requests per second, after this
change was made. To understand why, try out the malloc_test benchmark
which calls malloc() + realloc() in a loop across many threads, which
sees a a 250x improvement in process clock time and 200x on wall time

The tradeoff is this adds ~25ns of latency to individual malloc calls
compared to MODE=tiny, once the cosmo runtime has transitioned into a
fully multi-threaded state. If you don't need malloc() to be scalable
then cosmo provides many options for you. For starters the heap count
variable above can be set to put the process back in single heap mode
plus you can go even faster still, if you include tinymalloc.inc like
many of the programs in tool/build/.. are already doing since that'll
shave tens of kb off your binary footprint too. Theres also MODE=tiny
which is configured to use just 1 plain old dlmalloc arena by default

Another tradeoff is we need more memory now (except in MODE=tiny), to
track the provenance of memory allocation. This is so allocations can
be freely shared across threads, and because OSes can reschedule code
to different CPUs at any time.
2024-06-05 02:02:14 -07:00
..
aarch64 Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
argon2 Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
awk Add sysctlbyname() for MacOS 2024-05-02 23:21:43 -07:00
bash Implement proper time zone support 2024-05-04 23:06:37 -07:00
bzip2 Implement proper time zone support 2024-05-04 23:06:37 -07:00
chibicc Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
compiler_rt Make malloc() go 200x faster 2024-06-05 02:02:14 -07:00
ctags Implement proper time zone support 2024-05-04 23:06:37 -07:00
dlmalloc Make malloc() go 200x faster 2024-06-05 02:02:14 -07:00
double-conversion Make malloc() go 200x faster 2024-06-05 02:02:14 -07:00
finger Implement proper time zone support 2024-05-04 23:06:37 -07:00
gdtoa Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
getopt Make malloc() go 200x faster 2024-06-05 02:02:14 -07:00
hiredis Implement proper time zone support 2024-05-04 23:06:37 -07:00
intel Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
less Stop using .com extension in monorepo 2024-03-03 03:12:19 -08:00
libcxx Document __demangle() and fix a const func ptr bug 2024-06-02 04:15:48 -07:00
libcxxabi Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
libunwind Make malloc() go 200x faster 2024-06-05 02:02:14 -07:00
linenoise Drop support for Windows 8 2024-05-29 19:37:47 -07:00
lua Make malloc() go 200x faster 2024-06-05 02:02:14 -07:00
lz4cli Implement proper time zone support 2024-05-04 23:06:37 -07:00
make Introduce --timelog=FILE flag to GNU Make 2024-05-25 14:50:20 -07:00
maxmind Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
mbedtls Implement proper time zone support 2024-05-04 23:06:37 -07:00
musl Revert "Remove zlib namespacing (#1142)" 2024-05-14 20:45:23 -07:00
ncurses more modeline errata (#1019) 2023-12-16 23:07:10 -05:00
nsync Stop using .com extension in monorepo 2024-03-03 03:12:19 -08:00
openmp Add some noexcept annotations 2024-06-01 03:19:53 -07:00
pcre Stop using .com extension in monorepo 2024-03-03 03:12:19 -08:00
puff Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
python Make malloc() go 200x faster 2024-06-05 02:02:14 -07:00
qemu more modeline errata (#1019) 2023-12-16 23:07:10 -05:00
readline Fix --ftrace on Windows 2024-01-01 00:00:42 -08:00
regex Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
sed Implement proper time zone support 2024-05-04 23:06:37 -07:00
smallz4 Implement proper time zone support 2024-05-04 23:06:37 -07:00
sqlite3 Implement proper time zone support 2024-05-04 23:06:37 -07:00
stb Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
tidy Implement proper time zone support 2024-05-04 23:06:37 -07:00
tr Stop using .com extension in monorepo 2024-03-03 03:12:19 -08:00
tree Implement proper time zone support 2024-05-04 23:06:37 -07:00
tz Update MODE=tiny time zone list (#1167) 2024-05-06 16:48:49 -07:00
unzip Implement proper time zone support 2024-05-04 23:06:37 -07:00
vqsort more modeline errata (#1019) 2023-12-16 23:07:10 -05:00
xed Rename _bsr/_bsf to bsr/bsf 2024-03-04 17:33:26 -08:00
xxhash Implement proper time zone support 2024-05-04 23:06:37 -07:00
zip Revert "Remove zlib namespacing (#1142)" 2024-05-14 20:45:23 -07:00
zlib Support avx512f + vpclmulqdq crc32() acceleration 2024-05-29 10:13:37 -07:00
zstd Implement proper time zone support 2024-05-04 23:06:37 -07:00
.clang-format Reduce header complexity 2023-11-28 14:39:42 -08:00
BUILD.mk Implement proper time zone support 2024-05-04 23:06:37 -07:00