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

SqueakJS V2 (WIP) #168

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft

SqueakJS V2 (WIP) #168

wants to merge 10 commits into from

Conversation

codefrau
Copy link
Owner

@codefrau codefrau commented Jun 6, 2024

Goals of V2: see README

This PR mainly exists as a place for discussion.

@LinqLover
Copy link
Contributor

Interesting, thanks for sharing! Am I qualified to ask one or two questions? :-)

  1. About:

    Still need to decide between named inst vars (using inst var names from image) or suffixed (like p0, p1, ...)

    Just curious, are instance variable names a concept that the VM should be aware of at all? Or could I in theory create a new subclass manual in my image, do not assign names to the variables but only address them via indexes, and complain if SqueakJS cannot handle this class? Also, could there be valid Smalltalk variable names that are not allowed in JavaScript (I know the ClassBuilder is pretty restrictive but maybe it would not have to be)?

  2. What order of magnitude of speed-ups do you think each of these design changes will yield? Is there any bottleneck analysis publicly available?

Sorry if this is out of topic ...

@codefrau
Copy link
Owner Author

codefrau commented Jun 6, 2024

are instance variable names a concept that the VM should be aware of at all? Or could I in theory create a new subclass manual in my image, do not assign names to the variables but only address them via indexes, and complain if SqueakJS cannot handle this class?

If no suitable inst var name string can be found, we can easily generate a name like p0, p1 etc. Same when sanitizing names.

  1. What order of magnitude of speed-ups do you think each of these design changes will yield? Is there any bottleneck analysis publicly available?

See here, in particular this section. I haven't done a complete analysis though. This is still a hobby for me ;)

I believe we can overall get a 10x improvement in send speed. That would get us to within a magnitude of Cog.

@bpieber
Copy link

bpieber commented Jun 6, 2024

I love the fact that SqueakJS runs a recent Cuis image. It pauses often when using it, though. I wonder if porting the VectorEnginePlugin would help and be feasible? Juan also mentioned the possibility to implement the VectorCanvas using Web APIs. Maybe that would be easier?

@codefrau
Copy link
Owner Author

codefrau commented Jun 6, 2024

@bpieber This is independent of v2. I just opened #169 for it, please continue this discussion there.

@LinqLover
Copy link
Contributor

@codefrau Very interesting read, thank you! :-)

codefrau added 4 commits June 11, 2024 16:51
This uses Smalltalk inst var names for property names prefixed with a `$` (e.g. a Point would use `{ $x: 3, $y: 4 }` in JS). Indexable fields are in an array named `$$` (e.g. in Context you would have `{$sender: ..., $$: [tmp0, tmp1, ...]}`.

The `.pointers` property is now a proxy to allow the rest of the VM and primitives to still work. The JIT and optimized primitives will not use this proxy.
@codefrau
Copy link
Owner Author

codefrau commented Jun 12, 2024

I implemented actual var names, see b6a32be

The VM still works thanks to the .pointers now being a proxy to those explicit inst vars.

I tried it with various images (old, new, 32-bit, 64-bit) but it may be helpful if you could try others too. Everything should work as before, just slower.

@codefrau codefrau mentioned this pull request Jun 15, 2024
@gkgoat1
Copy link

gkgoat1 commented Dec 16, 2024

Could we port v2 to ESM and JS-native classes, considering as, iirc, Lively4 and Lively Next support it, in addition to most non-Lively coding environments and tools?

@codefrau
Copy link
Owner Author

Could we port v2 to ESM and JS-native classes, considering as, iirc, Lively4 and Lively Next support it, in addition to most non-Lively coding environments and tools?

I'm not sure how much we would gain from that. We would lose the ability to use the Lively tools at Dan's Smalltalk Zoo though.

So I'm not entirely opposed but it's definitely not a priority for me since the behavior wouldn't change at all and v2 is about better behavior.

@gkgoat1
Copy link

gkgoat1 commented Dec 16, 2024

Could we port v2 to ESM and JS-native classes, considering as, iirc, Lively4 and Lively Next support it, in addition to most non-Lively coding environments and tools?

I'm not sure how much we would gain from that. We would lose the ability to use the Lively tools at Dan's Smalltalk Zoo though.

That might present an issue, unless Smalltalk Zoo is updated.

So I'm not entirely opposed but it's definitely not a priority for me since the behavior wouldn't change at all and v2 is about better behavior.

My particular issue is about the usage of globals and extension methods, which make SqueakJS hard to optimize, especially AOT, and hard to scope (what if there are two SqueakJSs on one page?).

@codefrau
Copy link
Owner Author

codefrau commented Dec 16, 2024

We would lose the ability to use the Lively tools at Dan's Smalltalk Zoo though.

That might present an issue, unless Smalltalk Zoo is updated.

Dan is not getting any younger, I doubt that would happen.

My particular issue is about the usage of globals and extension methods, which make SqueakJS hard to optimize, especially AOT, and hard to scope (what if there are two SqueakJSs on one page?).

The majority of run time will be spent inside of generated code once the new JIT is in place. I don't think spending much effort to optimize the support code is worth the trouble.

BTW what AOT are you envisioning?

@gkgoat1
Copy link

gkgoat1 commented Dec 16, 2024

BTW what AOT are you envisioning?

Compiling SqueakJS, with a "factory" image, into an appropriate binary with ComponentizeJS or similar tools (for similar purposes as Sugar's EToys integration for my projects)

@codefrau
Copy link
Owner Author

Compiling SqueakJS, with a "factory" image, into an appropriate binary with ComponentizeJS or similar tools (for similar purposes as Sugar's EToys integration for my projects)

I'm sorry, targeting WebAssembly in that way is madness and would result in a much slower execution and a more bloated download. I could elaborate but not on here. We need to take this discussion elsewhere because it's getting very much away from SqueakJS V2. Please continue on the mailing list, preferably vm-dev. If you don't like that, open a separate ticket (but you would get more people to engage on a mailing list)

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