Skip to content

Make the lua function dgn.vault_at return a pointer - #4650

Merged
gammafunk merged 1 commit into
crawl:masterfrom
WizardIke:make_lua_function_vault_at_return_a_reference
Jul 29, 2026
Merged

Make the lua function dgn.vault_at return a pointer#4650
gammafunk merged 1 commit into
crawl:masterfrom
WizardIke:make_lua_function_vault_at_return_a_reference

Conversation

@WizardIke

Copy link
Copy Markdown
Contributor

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.

@regret-index regret-index added lua lua-based aspects of dcss Technical Bugfixes and backend refactoring / improvements labels Oct 27, 2025
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
gammafunk force-pushed the make_lua_function_vault_at_return_a_reference branch from f7f2a39 to f86be39 Compare July 28, 2026 23:06
@gammafunk
gammafunk merged commit e5bf83d into crawl:master Jul 29, 2026
53 checks passed
@gammafunk

Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lua lua-based aspects of dcss Technical Bugfixes and backend refactoring / improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants