Optimize and improve lualib#1128
Closed
GlassBricks wants to merge 53 commits intoTypeScriptToLua:masterfrom
Closed
Optimize and improve lualib#1128GlassBricks wants to merge 53 commits intoTypeScriptToLua:masterfrom
GlassBricks wants to merge 53 commits intoTypeScriptToLua:masterfrom
Conversation
Contributor
Author
|
The above commit addresses #1130. |
Contributor
Author
|
I'll eventually rebase to cleanup the commit tree |
…p-base # Conflicts: # src/transformation/visitors/literal.ts
String manipulation is slow in lua, and one table.concat operation is much faster than many string concatenations
11a9e40 to
db04b77
Compare
Contributor
|
fantastic work! |
Contributor
Author
|
Will wait until (possible) lualib refactor before finishing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Significantly optimizes array builtin function calls. EDIT: and other lualib impovements
This depends on both runtime-benchmark and preceding-statements pull requests. If and when those get merged I'll rebase.
Implementation notes:
EDIT: no longer relevant:
General optimization methods:
array = array.concat(...)items[]instead of...items[]. This allows optimizing cases such asarray.push(...anotherArray), and also is slightly faster than vararg anyways (based on my local benchmarks). This does however create backwards incompatibilities#arrayis actually a O(lgN) operation; so length is stored/computed where possiblearr[i-1], which gets translated to lua asarr[i]), avoiding an addition on every indexing. Based on my benchmarks, even if this happens only once in a simple loop, this gives a ~10% speedupfor(const i of $range(...)). This both helps in "storing"#arrayso it isn't recomputed, seems to be friendlier to the compiler (measurable speedup in some cases), and is faster thanipairs. I assume the potential behavior change (due to metatables) isn't an issue because lualib already wasn't consistent in usingipairsor numeric indexesSome particular methods:
array.push(oneElement)is optimized to something likearray[#array+1] = oneElement(+ changes for execution order). This is the most significant optimizationarray.join()is replaced with essentially anarray.map+table.concatcall -- lua string manipulation is very slow, and one table.concat call is much faster than many concatsarray.shift()is inlined (sincearray.pop()already is?)Other:
Benchmarks running on my local machine, for lua5.3 (Note: I changed the benchmarks to run x5 times for more stable results):
runtime