Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use computed goto in the VM #461

Closed
adazem009 opened this issue Jan 29, 2024 · 8 comments
Closed

Don't use computed goto in the VM #461

adazem009 opened this issue Jan 29, 2024 · 8 comments
Labels
P4 Priority: Trivial task

Comments

@adazem009
Copy link
Contributor

src/engine/virtualmachine_p.cpp
Compilers will turn the switch statement into computed goto automatically.

@adazem009 adazem009 added good first issue Good for newcomers task P4 Priority: Trivial labels Jan 29, 2024
@adazem009
Copy link
Contributor Author

@Arcnor What do you think about this?

@Arcnor
Copy link
Contributor

Arcnor commented Jan 29, 2024

You mean, removing the computed goto and relying on the compiler?

From what I've seen, the compiler might do something like that, but it's not controllable nor guaranteed, so maybe you want to keep the existing behavior until tests are done? After my changes, testing if this is getting done by the various compilers should be easy.

@Arcnor
Copy link
Contributor

Arcnor commented Jan 29, 2024

That said cleaner code should probably prevail, given this VM probably doesn't need the highest performance anyway...

@adazem009
Copy link
Contributor Author

adazem009 commented Jan 30, 2024

That said cleaner code should probably prevail, given this VM probably doesn't need the highest performance anyway...

Actually, the VM needs high performance. I've been even thinking about implementing JIT compilation.

I'll of course do benchmarks and tests first to be sure the compiler uses computed goto, that's why I've given this issue the lowest priority.

@Arcnor
Copy link
Contributor

Arcnor commented Jan 30, 2024

Actually, the VM needs high performance. I've been even thinking about implementing JIT compilation.

Isn't this project meant to be used with Scratch, the learning platform? For those kind of projects I think even a normal interpreted loop will suffice, unless you have some special targets in mind or something... Writing a JIT is possible, but a project on its own (like LuaJit), specially if doing it in general instead of using something like LLVM's ORC, but I'd be interested in seeing your ideas and progress there.

@adazem009
Copy link
Contributor Author

Actually, the VM needs high performance. I've been even thinking about implementing JIT compilation.

Isn't this project meant to be used with Scratch, the learning platform? For those kind of projects I think even a normal interpreted loop will suffice, unless you have some special targets in mind or something... Writing a JIT is possible, but a project on its own (like LuaJit), specially if doing it in general instead of using something like LLVM's ORC, but I'd be interested in seeing your ideas and progress there.

There are many cases where performance is needed, for example in 3D projects. Check these out, for example:
https://turbowarp.org/868045282
https://turbowarp.org/869264071

TurboWarp is a Scratch mod that compiles Scratch scripts to JavaScript. These projects would be much slower (or not run at all) if you tried them in the original Scratch VM. See https://docs.turbowarp.org/how

I don't think I'll ever be able to beat TurboWarp with this project, but I believe it's possible with JIT compilation.

@Arcnor
Copy link
Contributor

Arcnor commented Jan 30, 2024

I see, so very special projects, that's definitely not what I think of when I think about Scratch 😄 . Very cool nonetheless!

And for sure, beating V8 is probably very difficult if not impossible, although your surface area might be much smaller, so YMMV. Let me know when you open the issue to work on that, I'd be interested in following, and maybe even contribute if time permits.

@adazem009 adazem009 removed the good first issue Good for newcomers label Feb 7, 2024
@adazem009
Copy link
Contributor Author

Closing because the bytecode VM is going to be removed (#574).

@adazem009 adazem009 closed this as not planned Won't fix, can't repro, duplicate, stale Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P4 Priority: Trivial task
Projects
None yet
Development

No branches or pull requests

2 participants