mirror of
https://github.com/luau-lang/luau.git
synced 2025-01-20 01:38:07 +00:00
f5303b3dd7
table.concat is idiomatic and should be the fastest way to concatenate all table array elements together, but apparently you can beat it by using `string.format`, `string.rep` and `table.unpack`: ```lua string.format(string.rep("%*", #t), table.unpack(t)) ``` ... this just won't do, so we should fix table.concat performance. The deficit comes from two places: - rawgeti overhead followed by other stack accesses, all to extract a string from what is almost always an in-bounds array lookup - addlstring overhead in case separator is empty (extra function calls) This change fixes this by using a fast path for in-bounds array lookup for a string. Note that `table.concat` also supports numbers (these need to be converted to strings which is a little cumbersome and has innate overhead), and out-of-bounds accesses*. In these cases we fall back to the old implementation. To trigger out-of-bounds accesses, you need to skip the past-array-end element (which is nil per array invariant), but this is achievable because table.concat supports offset+length arguments. This should almost never come up in practice but the per-element branches et al are fairly cheap compared to the eventual string copy/alloc anyway. This change makes table.concat ~2x faster when the separator is empty; the table.concat benchmark shows +40% gains but it uses a variety of string separators of different lengths so it doesn't get the full benefit from this change. --------- Co-authored-by: vegorov-rbx <75688451+vegorov-rbx@users.noreply.github.com> |
||
---|---|---|
.. | ||
apicalls.lua | ||
assert.lua | ||
attrib.lua | ||
basic.lua | ||
bitwise.lua | ||
buffers.lua | ||
calls.lua | ||
clear.lua | ||
closure.lua | ||
constructs.lua | ||
coroutine.lua | ||
coverage.lua | ||
datetime.lua | ||
debug.lua | ||
debugger.lua | ||
errors.lua | ||
events.lua | ||
exceptions.lua | ||
gc.lua | ||
ifelseexpr.lua | ||
interrupt.lua | ||
iter.lua | ||
literals.lua | ||
locals.lua | ||
math.lua | ||
move.lua | ||
native.lua | ||
native_types.lua | ||
ndebug_upvalues.lua | ||
pcall.lua | ||
pm.lua | ||
safeenv.lua | ||
sort.lua | ||
strconv.lua | ||
stringinterp.lua | ||
strings.lua | ||
tables.lua | ||
tmerror.lua | ||
tpack.lua | ||
types.lua | ||
userdata.lua | ||
utf8.lua | ||
vararg.lua | ||
vector.lua |