Skip to content

Optimize lualib functions#1217

Merged
Perryvw merged 7 commits intoTypeScriptToLua:masterfrom
GlassBricks:optimize-array-operations
Apr 2, 2022
Merged

Optimize lualib functions#1217
Perryvw merged 7 commits intoTypeScriptToLua:masterfrom
GlassBricks:optimize-array-operations

Conversation

@GlassBricks
Copy link
Copy Markdown
Contributor

@GlassBricks GlassBricks commented Feb 25, 2022

Optimizes lualib functions.
Also fixes #1130.
Depends on #1213, however it can be made independent.

Array.push with only 1 argument gets even more optimization, as it is very common:

  • Pushing a single element results in array[#array + 1] = el
  • Pushing a spread array of elements uses a new function ArrayPushArray to avoid unpacking/repacking the array.

Benchmarks on my machine show 10-70% time reduction for most functions on lua5.3 and luajit. As can be expected, lua5.3 has better relative improvement for many functions compared to luajit.

Some optimization methods

  • caching global functions in local variables (when used more than once)
  • using a lua for i in range loop to iterate arrays

@GlassBricks GlassBricks marked this pull request as draft February 25, 2022 02:28
@Zamiell
Copy link
Copy Markdown
Contributor

Zamiell commented Feb 26, 2022

Super excited for this! Well done glass!

@GlassBricks GlassBricks force-pushed the optimize-array-operations branch from 3e8be7f to fce4580 Compare March 15, 2022 02:31
@GlassBricks GlassBricks force-pushed the optimize-array-operations branch from fce4580 to 4a68d9c Compare March 17, 2022 21:00
@GlassBricks GlassBricks marked this pull request as ready for review March 17, 2022 21:02
@GlassBricks GlassBricks requested a review from Perryvw April 2, 2022 17:58
@Perryvw Perryvw merged commit b5159f0 into TypeScriptToLua:master Apr 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Array.prototype methods are missing thisArg

3 participants