Make the lua function dgn.vault_at return a pointer - #4650
Merged
gammafunk merged 1 commit intoJul 29, 2026
Merged
Conversation
The lua function dgn.vault_at was returning a copy of the vault_placemnt at a location. Unfortunately, it is slow to copy a vault_placement and because the object returned to lua is a wrapper around a c++ object lua doesn't know how big it is and won't trigger garbage collection until you have about 8000 of them (about 17 MB). The only place using dgn.vault_at is the disco Pan colour function which can work just fine with a pointer rather than a copy and runs considerably faster. This is also consistent with the c++ equivalent that returns a pointer.
gammafunk
force-pushed
the
make_lua_function_vault_at_return_a_reference
branch
from
July 28, 2026 23:06
f7f2a39 to
f86be39
Compare
Member
|
We saw a crash recently from particleface that illustrated the problem of this expensive copy, since it was an OOM: https://cbro.berotato.org/morgue/particleface/crash-particleface-20260728-135654.txt Hence it was a good time to take a closer look at this fix and merge. Using a pointer without the full copy seems great here. |
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.
The lua function dgn.vault_at was returning a copy of the vault_placemnt at a location. Unfortunately, it is slow to copy a vault_placement and because the object returned to lua is a wrapper around a c++ object lua doesn't know how big it is and won't trigger garbage collection until you have about 8000 of them (about 17 MB).
The only place using dgn.vault_at is the disco Pan colour function which can work just fine with a pointer rather than a copy and runs considerably faster.
This is also consistent with the c++ equivalent that returns a pointer.