Re: SqueakJS

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: SqueakJS

Bert Freudenberg

On 23.11.2014, at 05:51, Jerry Bell <[hidden email]> wrote:

Hi Bert,

That shouldn’t have been necessary … I specifically wrote it using the original syntax so it would work even in old images where the Compiler does not know about named primitives yet. What exactly didn’t work? 

If I use the original syntax, I just get an "Error: a primitive has failed" error.  I have no idea what might cause it. 

Ah, the compiler now optimizes away the unused literal array:

(JS compiledMethodAt: #doesNotUnderstand:) literals
==> #(#primitiveFailed)

whereas the old Squeak compiler leaves it in:

(JS compiledMethodAt: #doesNotUnderstand:) literals
==> #((JavaScriptPlugin primitiveDoUnderstand 0 0) primitiveFailed)

The VM looks at the first literal to find the primitive. But I found a way to fool the compiler, which also makes the JS bridge work in current Squeak.

MVC strongly assumes that it has access to the pixels on the display. For example, if you open a menu, it renders the outline and text items on the display. Then, to highlight an item, it does not re-render it, but draws a rectangle in xor-mode, reversing all pixels. This is very efficient … provided you have direct access to pixels. Which you don’t have on a canvas - reading back pixels is slow. Canvas wants to be treated as a write-only surface.


OK, that is good to know.  Does Morphic have the same assumptions?

Conceptually it doesn’t, all drawing operates on a Canvas (an abstract class). However, the concrete class has always been FormCanvas, which does expose the underlying bitmap. There is code that makes use of that. But it shouldn’t be too hard to clean that up. E.g., there is also a PostScriptCanvas that can be used to generate a vector rendering. But it never has been used interactively, it’s just for printing. But making a JSCanvas subclass would be a reasonable course of action.

Older versions of Morphic are quite zippy compared to more recent ones (e.g. the Scratch image uses an old Morphic).

You go and build the ultimate run-everywhere object engine, and then you want to go and clutter it up with HTML? :)

As I said, it really depends on your goals :) My initial goal for SqueakJS was just to explore how far we can get in making existing Squeak images work. Which is why I only now added the JS bridge, because if you use it, that code won’t run anywhere else (not until we implement the JavaScriptPlugin for other VMs anyway, which is certainly possible by embedding v8/node, but not trivial, and then your code might still assume being run in a browser).

My questions on Canvas accelerated Squeak graphics are just random thoughts right now, before I go and start real work on my first real Squeak MVC web app. I am by no means a web expert, but whenever I am trying to build web applications it feels like I'm dealing with a tottering tower of kludges.  I think HTML may be fine for building a web page, but Canvas is the future for interactive web applications.   I don't want to spend my time trying to trick CSS into doing what I want, or trying to compensate for various subtle differences between browsers.  I just want to have the same complete control over what my web application does as I would if I were building a desktop application.   I think Canvas has the potential to provide that.

Sounds cool!

But, Canvas is pretty low level, you can draw pretty text but text layout is up to the programmer - and  there aren't many good Canvas frameworks out there yet.  Most assume you want to build a game.   There are a few exceptions, for example ZebKit looks pretty nice: http://www.zebkit.com, and SpreadJS is a nice fast spreadsheet component implemented using Canvas: http://wijmo.com/products/spreadjs/  - I've used SpreadJS in a UI with a few hundred thousand cells and it feels like a desktop app. 

I considered building a version of Morphic in Amber, but I didn't get too far- it was going to be a lot of work.  I had pretty much decided to build my next app in pure JavaScript using ZebKit.   And then I saw SqueakJS... Squeak in Canvas, easy to take advantage of existing JavaScript libraries, and fast enough to use for a real-world web app on an iPad (at least in MVC).  Good enough for me for now!

A couple more observations: one of the 'killer features' of Dart when running in a Dart VM is object memory snapshots, to speed up application loading - you already have this in SqueakJS using regular old JavaScript. 

Well, on startup SqueakJS still has to create a JavaScript object for each Smalltalk object, which takes more than a second for large images). I wonder … we could actually store the ready-made objects in IndexedDB … which would give us extremely fast image loading and saving. Now there’s an idea!

  Also, SpreadJS is nice, but un-minified it weighs in at 6.39MB, and minified it is 1.83MB.  The entire minimal-MVC image is 1.61MB.  I don't think download sizes will be too much of an issue for SqueakJS web apps!

Not sure if you have seen it, but the Makefile in the run/ directory combines VM and generated plugins into a single file (squeak-all.js, 1.1 MB). It minifies to 0.4MB and gzipping that results in just 0.1 MB :)

In summary, I don't really need any of the fancy Canvas accelerated graphics right now.  But, I think SqueakJS has a lot of potential, far beyond being just a way to run Squeak images in a web browser.  It seems to me that something pretty close to SqueakJS could be a lot like the Web should have been from the beginning! 

Indeed! This is pretty much why SqueakJS exists at all - as an experiment to build something using the Web as a universal runtime environment. If you take that experiment and make it do something useful, awesome!

Btw, for discussion not directly related to the VM, but how to build a system on top of it, we might rather want to move off vm-dev and continue on squeak-dev. CC’ed.

- Bert -






smime.p7s (5K) Download Attachment