Skip to content

Make Lua BIOS take use tail call optimisation#3266

Merged
payonel merged 1 commit intoMightyPirates:master-MC1.7.10from
skyem123:patch-1
Jun 8, 2022
Merged

Make Lua BIOS take use tail call optimisation#3266
payonel merged 1 commit intoMightyPirates:master-MC1.7.10from
skyem123:patch-1

Conversation

@skyem123
Copy link
Copy Markdown
Contributor

@skyem123 skyem123 commented Apr 3, 2020

I am not sure if this will do much, but for the sake of completeness I think it would be a good idea to do this.

I am not sure if this will do much, but for the sake of completeness I think it would be a good idea to do this.
@aiverson
Copy link
Copy Markdown

aiverson commented Oct 8, 2021

This seems like a good idea to me too. Because all of the variables except init in the bios are already wrapped in a do block, they will be out of scope when init is invoked, but init itself won't be. The lack of a tail call means that the bios invocation will stay on the stack, which will anchor the function prototype of the chunk of the bios, which will also prevent the bytecode loaded from the bios from being garbage collected, which is a kilobyte or so of RAM being released by this change. (machine.lua doesn't hold a reference to the bios after creating the coroutine to run it in)
The local variables of the frame would also be held in the stack preventing their collection, which includes all of the code loaded from init. If the code loaded from init is just responsible for loading some other more complicated operating system and then tail-call into it, this would allow more of the memory involved in the loading to be reclaimed. Openloader for instance. (Openloader should also get this tail call optimization patch applied.)

@payonel
Copy link
Copy Markdown
Member

payonel commented Jun 8, 2022

did some local testing, this seems good

@payonel payonel merged commit 9d2d619 into MightyPirates:master-MC1.7.10 Jun 8, 2022
@asiekierka asiekierka added this to the OC 1.7.6 milestone Jun 8, 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.

4 participants