Skip to content

Conversation

@corpserot
Copy link
Contributor

@corpserot corpserot commented Apr 22, 2025

Problem

In the current implementation, the luacontroller memory and disk is read and write on every event. This is a problem because it's rather expensive and users cannot control how it's used. More often than not, nothing actually changed to these things during an event.

Proposed solution

(credit to frog for the idea) Instead of automagically having mem and disks variables be read-write in each event, instead that responsibility is passed to the user through these functions:

  • read_mem() and write_mem()
  • read_disk(), write_disk(), available_disks() and available_disk_names()
  • For people that truly need speed, even links was reworked into read_links().

Because of the breaking change, the editor had to be adapted too. I've added some extra quality of life things and fixes. Most of the changes are in the disk tab.

TODO

  • additionally. carefully enable JIT optimization (and disable time checking) in parts of the built-in functions.
  • benchmark when JIT is enabled and disabled for luacontroller functions.

it should result in less overall computation in editor and main sandbox.
But unfortunately, without luajit optimizations this doesn't work. (see next commits)

extras:
- modified the basic editor to use the new API.
- added some quality of life extras to basic editor.
- updated help page about memory, disk and links.
Notably, these functions also 'escapes' from
libox's time tracking. This might be dangerous,
but it's unlikely to cause problems...
(famous words i'm sure)
@TheEt1234
Copy link
Contributor

TheEt1234 commented Apr 22, 2025

For people that truly need speed, even links was reworked into read_links().

please don't do this, it feels pointless

return libf(function(...)
local hook = {debug.gethook()}
debug.sethook()
jit.on(true, true)
Copy link
Contributor

@TheEt1234 TheEt1234 Apr 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok so apparently you can do jit.on(func, true) instead, i think that's a better solution

jit.off also flushes away any optimizations

@corpserot corpserot changed the title Rework luacontroller memory, disk, links + Enable JIT for luacontroller functions Rework luacontroller memory, disk Apr 24, 2025
@TheEt1234
Copy link
Contributor

TheEt1234 commented Apr 29, 2025

is this merge-able or are you still working on it

@corpserot
Copy link
Contributor Author

oh i forgot to say that. it's ready for merge/review.

@TheEt1234
Copy link
Contributor

hmm i should review this

Copy link
Contributor

@TheEt1234 TheEt1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM just needs a few changes

corpserot added 3 commits May 3, 2025 11:18
- sbz now (primarily) uses LuaJIT
- luacontroller read_disk() and write_disk() now checks for NaN
- typo fix
- don't escape terminal_text twice when rendering
  formspec
- initialize mem.current_tab when punching editor
@corpserot
Copy link
Contributor Author

ready to merge

@TheEt1234
Copy link
Contributor

ok, @ChefZander you should merge it

@ChefZander ChefZander merged commit 1b36462 into ChefZander:master May 3, 2025
1 check passed
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.

3 participants