Login
You're viewing the ruby.social public feed.
  • Nov 4, 2026, 11:03 PM

    Could you run love2d directly through emscripten, and then use weval to turn your love2d game into an optimized web build?

    💬 2🔄 0⭐ 0

Replies

  • Nov 5, 2026, 1:09 PM

    I'd also be very curious to see what would happen if you ran an emulator + ROM through a specializing compiler... Theoretically, that'd be the mythical perfect NES-to-native-exe compiler, right?

    💬 1🔄 0⭐ 0
  • Nov 5, 2026, 6:43 PM

    ah, ok! I'd looked over some of the weval blog posts, but the actual workings of things hadn't quite clicked for me. found these slides from a 2024 presentation:
    bernsteinbear.com/assets/img/w

    you use it by calling a function that says "partially evaluate this function with these constant values, and give me back a function pointer". from the point of view of your program, it might give you one or it might not; whenever you want to call it, you need to check.

    💬 1🔄 0⭐ 0
  • Nov 5, 2026, 6:54 PM

    So you don't really partially evaluate the whole thing, you kinda flag "here are the bits you should try to try to specialize" and weval fills in these spaces of the program with faster functions for it to call

    An important constraint of that interface is that those functions should return! So an emulator that just runs a half-dozen interleaved loops forever, and has no concept of function boundaries, is not really structured in a way that is going to play nicely with this tool

    💬 1🔄 0⭐ 0
  • Nov 5, 2026, 7:02 PM

    You should be able to annotate a Lua interpreter such that it specializes every chunk of code it compiles, I think. You _might_ be able to tell it to use wasm locals, but idk, my memory of the lua API is that it's _incredibly_ stack oriented and there's no obvious concept of a base pointer. I'll have to dig into the VM itself a bit. Coroutines might screw with things too, not sure.

    💬 1🔄 0⭐ 0
  • Nov 6, 2026, 3:49 AM

    Today I convinced nix to produce a WASI-compatible PUC Lua build with clang. nixpkgs' cross-compilation support made this fairy simple, though as always nix's documentation is terrible, and it took a bunch of false starts before I figured out how to actually do it. Now I get to do the fun part.

    💬 1🔄 0⭐ 0
  • 💬 2🔄 0⭐ 0
  • Nov 8, 2026, 12:54 AM

    I have figured out how to use "wizer" to create a .wasm module where Lua has been preinitialized and a benchmark program has been loaded and compiled down to bytecode, and will immediately start executing when "main" is called. Once I've annotated the interpreter, this is what will get passed to "weval" for partial evaluation shenanigans.

    💬 1🔄 0⭐ 0
  • Nov 8, 2026, 1:21 AM

    The particular suite of Lua benchmarks I turned up also checks timings for LuaJITs non-JIT mode, which I forgot existed... I suspect LuaJIT's interpreter would be a _much_ better target for this than PUC Lua, because LuaJIT optimizes the data structure for tables and only turns into a generic hashtable and dispatches to metatables when absolutely necessary. Make optimisations like _that_ visible to the partial evaluator and you're _really_ cooking.

    💬 1🔄 0⭐ 0
  • Nov 12, 2026, 3:36 AM

    I have coerced the benchmark runner into running my .wasm modules and producing this nice graph as part of a nix build. Very strange to me that lua-5.5.1-wasm (the normal Lua interpreter) seems to often measure noticably faster than lua-5.5.1-wizer (a .wasm file running exactly the same interpreter, except the source code already loaded and compiled to bytecode, ready to be executed)

    Pushed what I've got so far (which is mostly nix code) to my forgejo: git.information-superhighway.n

    A colourful graph with "Elapsed time" on the Y axis running from 0 to 4.5 seconds, and an unlabeled X axis that corresponds to 13 benchmark programs run on 6 different Lua interpreters (lua-5.5.1-native, luajit-2.1, luajit-2.1-interp, lua-5.5.1-wasm, lua-5.5.1-wizer, lua-5.5.1-weval).
luajit-2.1 is the fastest on every benchmark, followed by luajit-2.1-interp and lua-5.5.1-native. lua-5.5.1-wasm / lua-5.5.1-wizer / lua-5.5.1-weval cluster around last place.
    💬 1🔄 0⭐ 0
  • johnfarawaythyer@mastodon.social
    Nov 4, 2026, 11:22 PM

    @SpindleyQ I am very interested in better understanding the black magic by which love2d runs through emscripten

    💬 1🔄 0⭐ 0
  • Nov 4, 2026, 11:27 PM

    @farawaythyer afaik it doesn't... yet

    but it's definitely possible to compile it with regular Lua instead of LuaJIT, and emscripten is able to magically inject Fake Javascript SDL and some degree of OpenGL, so there's no obvious reason it shouldn't work!

    💬 1🔄 0⭐ 0
  • 💬 2🔄 0⭐ 0
  • Nov 5, 2026, 12:34 AM

    @farawaythyer @SpindleyQ There area a bunch of gotchas but lua+etc wasm works, mostly, love2d should be OKish (I roll my own engine) some browser restrictions which means there are some things you kind of have to design around, but no worse than say lua vs luajit issues. As for static builds I personally rely on too much luaness to static build that away, so possible but personally a bit of a dead end and you would have to *really* design your lua code for it.

    💬 0🔄 0⭐ 1
  • Nov 5, 2026, 12:38 AM

    RE: mastodon.social/@xriss/1175610

    @farawaythyer @SpindleyQ However I do feel the need for some sort of "compute" code to wasm maybe. Some thing to run alongside lua to do some heavy number crunching. Still pondering exactly how best to achieve that though. I guess I just want something that has the same sort of relationship to wasm as C used to have to, well, asm. And you know, builds/compiles/links live in a browser ( that last part is the tricky part)

    💬 0🔄 0⭐ 1
  • Nov 5, 2026, 1:23 AM

    @xriss I mean, the premise of weval is that the stuff that's genuinely static gets optimized, but worst-case the full interpreter is still there to fall back on. their main test case is automatically turning the entire SpiderMonkey javascript interpreter into a static-build wasm compiler and seeing worthwhile speedups, so I don't see why Lua couldn't work just as well

    💬 1🔄 0⭐ 0
  • Nov 5, 2026, 10:35 PM

    @SpindleyQ My problem is that with lua I already have C as an option, so I can already do this sort of thing intentionally. Where I do use lua, I tend to get up to all sort of shenanigans making use of its mutability. So either that sort of thing is already happening or wont help much. GC and small object churn is where I find lua takes the biggest hit compared to compiled code. LuaJIT kinda does all the sensible optimisations, so we just need a wasm version of that :)

    💬 0🔄 0⭐ 0
  • Nov 5, 2026, 1:41 AM

    @farawaythyer ah, so the hard work has already been done! excellent

    I'd say as long as you aren't doing intense shader or extra-weird filesystem stuff, it looks to me like love.js should probably work out fine. it's literally compiling the love2d source code directly; there's just a bit of jank around certain features because the web is weird.

    it is a shame that the love2d team doesn't just make this a first-class thing though.

    💬 1🔄 0⭐ 0
  • 💬 0🔄 0⭐ 0
  • Nov 6, 2026, 5:07 PM

    @SpindleyQ I didn't read the whole thread here but the "recompiled" retro game ports that have been happening work this way-- they translate machine code disassembly to C code. it is not LLM it is normal lovely healthy determinism

    💬 1🔄 0⭐ 0
  • Nov 6, 2026, 5:09 PM

    @SpindleyQ transcoding like this is so interesting to me. I enjoy doing it by hand as well as it is a very strange kind of refactoring (e.g. paste some C code into a .lua file and line by line make it Lua)

    💬 0🔄 0⭐ 0
  • Nov 7, 2026, 8:01 PM

    @PsySal it's really fascinating to me, because the theory of automatically deriving a compiler from an interpreter is from the 1970s, and it's actually pretty unreasonably effective, but in practice it's a very fringe idea, only a handful of "production-ready" language implementations work in this sort of way, and all the ones I know of (GraalVM, Pypy) are fairly modern and still kinda feel experimental.

    💬 1🔄 0⭐ 0
  • Nov 7, 2026, 8:36 PM

    @PsySal a modern JavaScript interpreter is like four different interpreters in a trenchcoat, that all make different performance tradeoffs and need to be kept in sync with each other by hand, and the whole sprawling nightmare is just kind of accepted as "well there's lots of JavaScript that needs to run fast so it's worth the investment"

    But like... If there's a technique where you can get 50% of the way there with, like, 0.0001% of the effort?? Woah Nelly sign me up, I want THAT

    💬 0🔄 0⭐ 0
  • 💬 0🔄 0⭐ 0