perf: O(1) upvalue access by storing upvalues as a tuple#155
Merged
davydog187 merged 1 commit intomainfrom Feb 27, 2026
Merged
Conversation
Convert the upvalue list stored in lua_closure tuples to an Erlang
tuple, enabling O(1) indexed access via elem/2 instead of O(N)
linear scans via Enum.at/2.
Changes:
- executor.ex :closure handler: wrap captured_upvalues with
List.to_tuple/1 before building the closure
- executor.ex get_upvalue/set_upvalue: Enum.at -> elem
- executor.ex :parent_upvalue case: Enum.at -> elem
- stdlib.ex lua_load: empty upvalues %{} -> {}
- test/support/lua_test_case.ex dofile helper: empty upvalues [] -> {}
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
16ecec4 to
4d4a145
Compare
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.
Summary
Convert the upvalue list stored in
{:lua_closure, proto, upvalues}from a list to an Erlang tuple, replacing O(N)Enum.at/2accesses with O(1)elem/2.Changes:
:closurehandler: wrapcaptured_upvalueswithList.to_tuple/1before building the closureget_upvalue/set_upvaluehandlers:Enum.at(upvalues, index)→elem(upvalues, index):parent_upvaluecase (inside closure capture):Enum.at→elemlua_load: empty upvalues%{}→{}[]→{}For deeply nested closures with many upvalues (e.g.
fibcapturing outer-scope variables), every upvalue read/write was O(N) in the number of upvalues. This makes it O(1).Test plan
🤖 Generated with Claude Code