mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 11:37:35 +00:00
3609f65de3
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. |
||
---|---|---|
.. | ||
test | ||
BUILD.mk | ||
cosmo.h | ||
lapi.c | ||
lapi.h | ||
lauxlib.c | ||
lauxlib.h | ||
lbaselib.c | ||
lcode.c | ||
lcode.h | ||
lcorolib.c | ||
lctype.h | ||
ldblib.c | ||
ldebug.c | ||
ldebug.h | ||
ldo.c | ||
ldo.h | ||
ldump.c | ||
lfunc.c | ||
lfunc.h | ||
lgc.c | ||
lgc.h | ||
linit.c | ||
liolib.c | ||
ljumptab.inc | ||
llex.c | ||
llex.h | ||
llimits.h | ||
llock.c | ||
lmathlib.c | ||
lmem.c | ||
lmem.h | ||
lnotice.c | ||
loadlib.c | ||
lobject.c | ||
lobject.h | ||
lopcodes.c | ||
lopcodes.h | ||
lopnames.inc | ||
loslib.c | ||
lparser.c | ||
lparser.h | ||
lprefix.h | ||
lrepl.c | ||
lrepl.h | ||
lstate.c | ||
lstate.h | ||
lstring.c | ||
lstring.h | ||
lstrlib.c | ||
ltable.c | ||
ltable.h | ||
ltablib.c | ||
ltests.c | ||
ltests.h | ||
ltm.c | ||
ltm.h | ||
lua.h | ||
lua.main.c | ||
luac.main.c | ||
luacallwithtrace.c | ||
luaconf.h | ||
luaencodejsondata.c | ||
luaencodeluadata.c | ||
luaencodeurl.c | ||
luaformatstack.c | ||
lualib.h | ||
luaparseurl.c | ||
luaprintstack.c | ||
luapushheader.c | ||
luapushheaders.c | ||
luapushlatin1.c | ||
luapushurlparams.c | ||
lundump.c | ||
lundump.h | ||
lunix.c | ||
lunix.h | ||
lutf8lib.c | ||
lvm.c | ||
lvm.h | ||
lzio.c | ||
lzio.h | ||
README.cosmo | ||
serialize.c | ||
tms.h | ||
visitor.c | ||
visitor.h |
DESCRIPTION Lua is a language designed for embedded use in native applications. It has an impossibly elegant C API and the Lua language itself feels more like Python compared to alternatives like Tcl except it's a great deal faster and doesn't have strong opinions about character encoding. PROVENANCE https://github.com/lua/lua/ commit e7803f7dbcdc966ab1f9db143424ee811ab1a398 Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br> Date: Wed Mar 3 09:44:20 2021 -0300 New release number (5.4.3) luac.c needed to be sourced from: https://www.lua.org/ftp/lua-5.4.3.tar.gz LOCAL MODIFICATIONS Lua now uses a bestline REPL with bash-style code completion. Integer literals such as `033` will now be interpreted as octal. Integer literals such as `0b10` will now be interpreted as binary. The `\e` string literal escape sequence has been added, which is equivalent to `\27` (the Lua version of `\033`) or the ASCII ESC character. It may be used for teletypewriter control like having bold text, which can be encoded elegantly as `\e[1mHELLO\e[0m`. Added luaL_traceback2() for function parameters in traceback. Added Python-like printf modulus operator for strings. Added Python-like printf multiply operator for strings. Fixed a buffer overflow in os.tmpname