cosmopolitan/third_party/lua
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
..
test Fix stdio for character device regression 2024-05-25 05:58:09 -07:00
BUILD.mk Make malloc() go 200x faster 2024-06-05 02:02:14 -07:00
cosmo.h Reduce header complexity 2023-11-28 14:39:42 -08:00
lapi.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
lapi.h Reduce header complexity 2023-11-28 14:39:42 -08:00
lauxlib.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
lauxlib.h Reduce header complexity 2023-11-28 14:39:42 -08:00
lbaselib.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
lcode.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
lcode.h Reduce header complexity 2023-11-28 14:39:42 -08:00
lcorolib.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
lctype.h Polish redbean serialization 2022-04-29 06:10:10 -07:00
ldblib.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
ldebug.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
ldebug.h Reduce header complexity 2023-11-28 14:39:42 -08:00
ldo.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
ldo.h Reduce header complexity 2023-11-28 14:39:42 -08:00
ldump.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
lfunc.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
lfunc.h Reduce header complexity 2023-11-28 14:39:42 -08:00
lgc.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
lgc.h Reduce header complexity 2023-11-28 14:39:42 -08:00
linit.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
liolib.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
ljumptab.inc Get Lua to build with all tests passing 2021-03-07 13:31:09 -08:00
llex.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
llex.h Reduce header complexity 2023-11-28 14:39:42 -08:00
llimits.h Reduce header complexity 2023-11-28 14:39:42 -08:00
llock.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
lmathlib.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
lmem.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
lmem.h Reduce header complexity 2023-11-28 14:39:42 -08:00
lnotice.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
loadlib.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
lobject.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
lobject.h Rename _bsr/_bsf to bsr/bsf 2024-03-04 17:33:26 -08:00
lopcodes.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
lopcodes.h Reduce header complexity 2023-11-28 14:39:42 -08:00
lopnames.inc Get Lua to build with all tests passing 2021-03-07 13:31:09 -08:00
loslib.c Fix buffer overflow in os.tmpname (#1180) 2024-05-20 03:46:27 -04:00
lparser.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
lparser.h Reduce header complexity 2023-11-28 14:39:42 -08:00
lprefix.h Make improvements 2022-04-24 10:06:05 -07:00
lrepl.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
lrepl.h Reduce header complexity 2023-11-28 14:39:42 -08:00
lstate.c Implement proper time zone support 2024-05-04 23:06:37 -07:00
lstate.h Reduce header complexity 2023-11-28 14:39:42 -08:00
lstring.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
lstring.h Reduce header complexity 2023-11-28 14:39:42 -08:00
lstrlib.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
ltable.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
ltable.h Reduce header complexity 2023-11-28 14:39:42 -08:00
ltablib.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
ltests.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
ltests.h Reduce header complexity 2023-11-28 14:39:42 -08:00
ltm.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
ltm.h Reduce header complexity 2023-11-28 14:39:42 -08:00
lua.h Reduce header complexity 2023-11-28 14:39:42 -08:00
lua.main.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
luac.main.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
luacallwithtrace.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
luaconf.h Reduce header complexity 2023-11-28 14:39:42 -08:00
luaencodejsondata.c Bring back gc() function 2024-01-08 10:26:28 -08:00
luaencodeluadata.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
luaencodeurl.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
luaformatstack.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
lualib.h Reduce header complexity 2023-11-28 14:39:42 -08:00
luaparseurl.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
luaprintstack.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
luapushheader.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
luapushheaders.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
luapushlatin1.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
luapushurlparams.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
lundump.c Reduce header complexity 2023-11-28 14:39:42 -08:00
lundump.h Reduce header complexity 2023-11-28 14:39:42 -08:00
lunix.c Implement proper time zone support 2024-05-04 23:06:37 -07:00
lunix.h Reduce header complexity 2023-11-28 14:39:42 -08:00
lutf8lib.c Reduce header complexity 2023-11-28 14:39:42 -08:00
lvm.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
lvm.h Reduce header complexity 2023-11-28 14:39:42 -08:00
lzio.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
lzio.h Reduce header complexity 2023-11-28 14:39:42 -08:00
README.cosmo Fix buffer overflow in os.tmpname (#1180) 2024-05-20 03:46:27 -04:00
serialize.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
tms.h Reduce header complexity 2023-11-28 14:39:42 -08:00
visitor.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
visitor.h Reduce header complexity 2023-11-28 14:39:42 -08:00

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