News for hackers. Stuff that matters.
Re:Google Docs will now use canvas based rendering by dangoor on Wednesday May 12, 2021 @01:33PM (#27132934)
In 2009, I joined Mozilla and started working on the Bespin[1] project, which Ben Galbraith & Dion Almaer had brought to Moz. Bespin was built with a canvas-based renderer. Bespin was way faster than other browser-based code editors at the time.

Then the Ajax.org/Cloud9 folks came along with their Ace editor[2], which was DOM-based and still very fast. We ended up merging the projects. edit to add: and switching to DOM rendering

Rik Arends[3] was one of the Ajax.org folks and he's been working on a WebGL-based code environment called Makepad[4], which is entirely built in Rust and has its own UI toolkit. He's complained a lot about how difficult it is to make a performant JS-based editing environment.

My point in all of this is just that there are absolutely tradeoffs in performance, accessibility, ease-of-development, internationalization, and likely other aspects. If raw performance is what you're going for, it's hard to beat just drawing on a canvas or using WebGL. Google Docs needs to worry about all of that other stuff, too, so I'll be interested to see how this shapes up.

[1]: https://en.wikipedia.org/wiki/Mozilla_Skywriter

[2]: https://en.wikipedia.org/wiki/Ace_(editor)

[3]: https://twitter.com/rikarends

[4]: https://makepad.dev

Re:Google Docs will now use canvas based rendering by jd3 on Wednesday May 12, 2021 @02:55PM (#27133832)
It's funny — Google's approach here reminds me of the Netscape/Mozilla XUL tree[0] element.

For those unfamiliar, the XUL tree is a performant 1990s-era virtualized list that is able to render millions to tens of millions of rows of content without slowdown since it gives you the option of rendering internally in Firefox rather than through the DOM.

I still don't completely understand why Mozilla is/was planning to axe[1][2] it since there's no web-based HTML5/JS replacement (the virtualized "tree" is implemented in C++, iirc) and it's still being actively used in places.{xul/xhtml}[3] and the Thunderbird/SeaMonkey[4][5] products.

It's interesting that both Google's canvas bet (Flutter, Docs, etc.) and the Mozilla XUL tree are basically trying to solve a nearly identical problem (DOM nodes are expensive and DOM manipulation is slow) ~20-25 years apart.

[0]: https://developer.mozilla.org/en-US/docs/Archive/Mozilla/XUL...

[1]: https://docs.google.com/document/d/1ORqed8SW_7fPnPdjfz42RoGf...

[2]: https://bugzilla.mozilla.org/show_bug.cgi?id=1446341

[3]: chrome://browser/content/places/places.xhtml

[4]: https://www.thunderbird.net/

[5]: https://www.seamonkey-project.org/

Re:Google Docs will now use canvas based rendering by pcwalton on Wednesday May 12, 2021 @04:14PM (#27134605)
> I still don't completely understand why Mozilla is/was planning to axe[1][2] it since there's no web-based HTML5/JS replacement (the virtualized "tree" is implemented in C++, iirc) and it's still being actively used in places.{xul/xhtml}[3] and the Thunderbird/SeaMonkey[4][5] products.

XUL is a maintenance burden and exacts a development tax on new features (having to make the Servo CSS engine support XUL so that it could be uplifted to Firefox was extremely annoying). It's also full of security problems, as it's written in '90s C++ that nobody is around to maintain properly. Getting rid of it is an inevitability.

Re:Google Docs will now use canvas based rendering by jd3 on Wednesday May 12, 2021 @04:50PM (#27135009)
Thanks for the reply! I'm a big fan of your work. I can only imagine the nightmare of trying to implement two separate XUL <=> HTML/CSS flex/box models in Servo/Rust.

For readers that are unaware, there is also a great blog post breaking down some of these points in finer detail [0][1].

I guess my question is — are there replacements planned for any of the legacy yet performant XPCOM interfaces / XUL elements like nsITreeView/tree? My tl;dr understanding of XUL trees is that the DOM is and always has been too slow to render millions of scrollable rows in a performant manner (bookmarks, thunderbird, etc.). Would it not be possible to re-implement the XUL tree logic in Rust, for example? Is the goal to completely get rid of all non-standards compliant elements in the long-run?

It seems like there will always be some custom elements necessary for a native desktop interface which can never be integrated into HTML...

"I’ve talked about this before, but things like panel, browser, the menu elements (menu, menupopup, menucaption, menuitem, menulist) don’t have HTML equivalents and are important for our desktop browser experience. While we could invent a way to do this in chrome HTML, I don’t think the cost/benefit justifies doing that ahead of the rest of the things in our list." [2]

..., yet I don't see much discussion about this anywhere.

I'm particularly interested because I'm currently working on a XULRunner project where a <tree> is central to the user interface (millions of rows, image column, embedded data, must run on macOS/Windows/Linux/*BSD, etc.), and it's a little alarming that there is an open bugzilla ticket that did not initially mention either the performance nor ecosystem implications (essentially kill Thunderbird, kill SeaMonkey more than it already has been) of its removal.

I think the one part I have trouble with is that implementing a native looking/performant cross-platform desktop UI is still a nightmare and XUL could have potentially been a fantastic desktop-focused superset/companion of/to HTML.

[0]: https://yoric.github.io/post/why-did-mozilla-remove-xul-addo...

[1]: https://news.ycombinator.com/item?id=24231017

[2]: https://briangrinstead.com/blog/xbl-replacement-newsletter-2...

Re:Google Docs will now use canvas based rendering by pcwalton on Wednesday May 12, 2021 @04:57PM (#27135067)
I mean, you probably won't like this answer, but I don't think you should be writing a XUL-based app in 2021 if you want it to be useful, as opposed to for fun. XUL is 25-year old legacy technology, and using it is an exercise in retrocomputing.
Re:Google Docs will now use canvas based rendering by jd3 on Wednesday May 12, 2021 @05:12PM (#27135210)
Fair enough.

Sorry, I should have clarified a bit more — I'm writing a cross-platform desktop application that has a preact[0] frontend (+ a Go backend) using `firefox --app application.ini`.

I have been experimenting with performant lists (which is why I brought up the XUL tree — it's currently central to the interface, though not the final implementation for sure) — I'm currently only using the XUL window/menubar elements in order to populate the native macOS menubar.

I am a fullstack web dev in my day job, so my goal here is to write a fast, easily extendable UI that I can quickly iterate upon using modern html/js/css/etc.

I love gecko and used to write XUL add-ons many years ago, so I'm already familiar with JS code modules, XPCOM, XUL, the internal browser architecture etc.

Basically, I'm now using XULRunner (`firefox --app application.ini` as previously mentioned — will eventually be stubbed into a native macOS .app/OS program) as a replacement for Electron / Chromium Embedded Framework[1].

I'm basically doing the same thing as Positron[2]/qbrt[3].

[0]: https://preactjs.com/

[1]: https://en.wikipedia.org/wiki/Chromium_Embedded_Framework

[2]: https://github.com/mozilla/positron

[3]: https://github.com/mozilla/qbrt

Re:Google Docs will now use canvas based rendering by girvo on Thursday May 13, 2021 @12:38AM (#27138467)
While you're definitely correct, I enjoyed working with Komodo IDE which was (is?) built around XUL even up to a few years ago. A neat API for extending and hacking around on it, with quite nice discoverability. I'm sad to see it go, but it makes perfect sense as to why!
Re:Google Docs will now use canvas based rendering by silon42 on Thursday May 13, 2021 @03:05PM (#27146012)
Probably still better than anything HTML.
Re:Google Docs will now use canvas based rendering by zxzax on Wednesday May 12, 2021 @06:58PM (#27136209)
I really doubt anyone is going to revive those old legacy widgets. That style of widget is flawed and predates MVC-style design, you'll find it becomes very impossible to present non-string data with that tree. Most applications now will want to show arbitrary widgets within the table, and for that they'll use the standard HTML/CSS. I would expect you can do something comparably fast by using a virtualized list in HTML, along with IndexedDB.
Re:Google Docs will now use canvas based rendering by MarkSweep on Wednesday May 12, 2021 @05:51PM (#27135589)
I'm not a XUL or JavaScript expert, but there is evidence that you can implement a virtualized list in regular HTML:

https://react-window.vercel.app/

Re:Google Docs will now use canvas based rendering by jd3 on Wednesday May 12, 2021 @06:02PM (#27135698)
I recently wrote a somewhat performant react-virtualized[0] list for a project at work, though it's definitely a bit trickier in plain HTML/JS.

As far as the XUL virtualized tree goes, a couple of Mozilla engineers wrote some examples using plain html/javascript + DOM node manipulation[1]. While promising, I can't imagine that this implementation could ever be as fast as the compiled C++ one[2].

[0]: https://github.com/bvaughn/react-virtualized

[1]: http://benbucksch.github.io/trex/fastlist-test.html

[2]: https://searchfox.org/mozilla-central/source/layout/xul/tree...

https://news.ycombinator.com/item?id=14158170

Re:Google Docs will now use canvas based rendering by jd3 on Wednesday May 12, 2021 @03:01PM (#27133897)
tangential but amusing — the old chrome://global/content/config.{xul/xhtml} used a XUL tree and rendered 0 DOM nodes to display its treechildren whereas the new about:config renders upwards of 4500 <tr> DOM nodes by default

ignoring the fact that you can no longer sort by specific columns (name, status, type, value, etc), you can really feel how slow the new implementation is if you click the "Show Only Modified Preferences" button — the DOM update feels incredibly sluggish whereas both searching and sorting columns in the old xul tree always felt snappy and instantaneous

https://imgur.com/a/abhYoW8

Re:Google Docs will now use canvas based rendering by lol768 on Wednesday May 12, 2021 @03:38PM (#27134283)
Yeah it's a real shame it's all moving to HTML/JS for the chrome & e.g. devtools, even if it's more "maintainable".
Re:Google Docs will now use canvas based rendering by jd3 on Wednesday May 12, 2021 @03:51PM (#27134386)
I use the modern Firefox HTML5/JS dev tools on a daily basis and love the featureset that they provide, though it is equally shocking to compare the feel to that of the old DOM Inspector[0] (and Venkman[1], the old JS debugger), which was a XUL add-on for DOM inspection that used to run in Firefox, Thunderbird, and SeaMonkey.

What feels snappy and instantaneous in DOM Inspector feels somewhat muddy and laggy in the modern devtools.

While I greatly appreciate the amount of features that Mozilla has integrated into the modern (post-firebug) devtools over the years, it is a little sad that the next generation will never get to experience just how fast some narrow aspects of web development used to be.

https://imgur.com/a/JZoSTXf

[0]: https://addons.thunderbird.net/en-us/firefox/addon/dom-inspe...

[1]: https://addons.thunderbird.net/en-us/firefox/addon/javascrip...

Re:Google Docs will now use canvas based rendering by cxr on Wednesday May 12, 2021 @06:26PM (#27135918)
Thanks for the shoutout to the legacy DOM Inspector (which I used to maintain) and Venkman (which I have both admired and used in anger). When Mozilla decided to put together a devtools team for Firefox 4, I was disappointed when I realized that they weren't going to take any effort to make sure the fruits of their labor sidestepped any of the performance issues that Firebug had exhibited for most of its lifetime. I do want to quibble, though, about the suggestion that this is a matter of XUL+JS versus HTML+JS. I say this even as someone with strong feelings about what a joy XUL was in comparison, and a long-lasting bitterness over the decision (among many) that Mozilla made in mishandling its own future.

WebKit's Web Inspector has for a long time gone with HTML, and in all its incarnations I've ever tried out, it has always been snappier than either Firebug and or the devtools that ships with Firefox.

When making comparisons like this, it's important to keep in mind that you're comparing/contrasting teams and their output, and it's not just a matter of the building blocks they're using. Some teams do better work than others.

Re:Google Docs will now use canvas based rendering by watersb on Thursday May 13, 2021 @11:23PM (#27150340)
Venkman!
Re:Google Docs will now use canvas based rendering by userbinator on Wednesday May 12, 2021 @11:07PM (#27137994)
It's all about quantity over quality, lowest-common-denominator crap. Quality and craftsmanship has gone down the drain with "modern" software.
Re:Google Docs will now use canvas based rendering by bscphil on Wednesday May 12, 2021 @07:07PM (#27136294)
Similarly, my understanding is that the TreeStyleTab extension was forced to migrate in the same manner and it can get very sluggish as well when you have a lot of tabs open.
Re:Google Docs will now use canvas based rendering by jd3 on Thursday May 20, 2021 @08:55PM (#27229332)
for future readers — ironically, there were actually WIP patches to re-implement the XUL tree (nsITreeView) using an HTML5 canvas years ago

https://bugzilla.mozilla.org/show_bug.cgi?id=441414#c172

---

  "What has been will be again,
  what has been done will be done again;
  there is nothing new under the sun."
—Ecclesiastes 1:9

"pining for a future that never arrived"

https://en.wikipedia.org/wiki/Mark_Fisher#Hauntology

Re:Google Docs will now use canvas based rendering by alisonkisk on Wednesday May 12, 2021 @03:41PM (#27134323)
Why can't XUL vs DOM just be the same data with a fast C++ API and a slow JS API?
Re:Google Docs will now use canvas based rendering by jd3 on Wednesday May 12, 2021 @04:15PM (#27134617)
> Why can't XUL vs DOM just be the same data with a fast C++ API and a slow JS API?

This is a great question! I'm not really qualified to answer it, but I'll give it a try.

My understanding is that the XUL tree is fast because it implements the XPCOM C++ nsITreeView[0][1][2] interface.

If you're writing a XULRunner program ...

(Firefox "is distributed as the combination of a Gecko XUL runtime — libxul, other shared libraries, and non-browser-specific resources like those in toolkit/ — plus a Firefox XUL application — mostly just the files in Contents/Resources/browser/, plus the 'firefox' stub executable that loads Gecko and points it at a XUL application", see [3])

..., XPCOM[4] allows you invoke those implemented interface methods directly from JavaScript.

XPCOM is a technology that, since the removal of XUL/XPCOM addons, is inaccessible to everyone except for Mozilla devs and those who write XULRunner programs using `firefox --app /path/to/application.ini`.

So, some XUL elements (like <tree>) implement an XPCOM interface that invokes native C++ (or rust, python, java, etc.) code, which is statically compiled directly into the Gecko XUL runtime.

Modern HTML5 elements, in general, must utilize the native interpreted browser DOM/JavaScript and cannot choose to implement/satisfy an arbitrary internal XPCOM interface. While I'm sure that Mozilla has figured out a way to make these elements fast (C++, Rust, I have no idea), you are always bounded by the limitations of the DOM.

So, my understanding is that, because we are relying on standards-compliant HTML5 elements which mutate the DOM, we cannot specify and implement new XPCOM interfaces ("with a fast C++ API") that could theoretically bypass the DOM — we /must/ rely on the "slow JS API."

[0]: https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/...

[1]: https://searchfox.org/mozilla-central/source/layout/xul/tree...

[2]: https://searchfox.org/mozilla-central/source/layout/xul/tree...

[3]: https://mykzilla.org/2017/03/08/positron-discontinued/#comme...

[4]: https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM

Re:Google Docs will now use canvas based rendering by IshKebab on Wednesday May 12, 2021 @05:16PM (#27135257)
Try holding down Alt on https://makepad.dev/

Such a cool feature that you can't really do with DOM based solutions (VSCode could never do this).

Re:Google Docs will now use canvas based rendering by rikarendsmp on Wednesday May 12, 2021 @05:27PM (#27135337)
It may sound stupid, but this was the feature i tried to add to ACE and i couldn't. And i spent the last decade trying to invent a drawing API that would let me do this effect.
Re:Google Docs will now use canvas based rendering by Gaelan on Wednesday May 12, 2021 @08:15PM (#27136834)
Would anyone mind explaining/screenshotting what it does, for the benefit of those of us on phones?
Re:Google Docs will now use canvas based rendering by igorbark on Wednesday May 12, 2021 @09:09PM (#27137288)
it basically folds (hides) the implementation code of every method in the file, giving an API-like view, but with a smooth animation shrinking the text instead of instantly disappearing it
Re:Google Docs will now use canvas based rendering by jamesfmilne on Thursday May 13, 2021 @01:49PM (#27145023)
Nnnnnnng, this is awesome, and annoying because it's so good. Imagine coupling it with the mouse wheel to zoom in/out.

I'd love to have this in MacVim/gvim somehow.

Re:Google Docs will now use canvas based rendering by skyde on Wednesday May 12, 2021 @01:49PM (#27133126)
Can someone explain why https://makepad.dev/ is extremely slow and "unusable" on Microsoft Edge browser but run smoothly on Chrome? Is it because of bad WebGL perf on JavasSript perf in general?
Re:Google Docs will now use canvas based rendering by slaymaker1907 on Wednesday May 12, 2021 @02:24PM (#27133495)
Did you try using dev/canary Edge? It should pretty much be the same rendering engine and JS engine as Chrome. Definitely report this to the Edge team if you have the time (very easy to do from the dev version of Edge). In my experience, they are very responsive to bug reports and feature suggestions.
Re:Google Docs will now use canvas based rendering by rikarendsmp on Wednesday May 12, 2021 @05:34PM (#27135419)
Back in the day i made it work on Edge on an xbox. This was microsofts browser +JS engine. Nowadays its just chrome though. If it has problems, i'd be highly surprised.
Re:Google Docs will now use canvas based rendering by tyingq on Wednesday May 12, 2021 @02:09PM (#27133352)
Another possibility is code that acts differently depending on user-agent.
Re:Google Docs will now use canvas based rendering by rikarendsmp on Wednesday May 12, 2021 @04:39PM (#27134898)
It most definitely does not.
Re:Google Docs will now use canvas based rendering by ComputerGuru on Wednesday May 12, 2021 @02:05PM (#27133318)
Edge or Edgium?
Re:Google Docs will now use canvas based rendering by yonl on Wednesday May 12, 2021 @02:21PM (#27133467)
For me, it's not very fast in chrome.
Re:Google Docs will now use canvas based rendering by fulafel on Thursday May 13, 2021 @01:38AM (#27138800)
You might be getting the software rendering webgl implementation if there are GPU driver problems (https://blog.chromium.org/2016/06/universal-rendering-with-s...).

(Of course in principle you don't need hardware acceleration to make this kind of thing run fast...)

Re:Google Docs will now use canvas based rendering by ehsankia on Wednesday May 12, 2021 @03:51PM (#27134392)
Can you give a bit more flavor to "not very fast"? I'm on a measly chromebook and scrolling, selecting text, expanding directories, everything is smooth and high framerate.

Is there a specific operation that is not fast? Opening it for the first time took a few seconds but afterwards it was pretty buttery.

Re:Google Docs will now use canvas based rendering by rikarendsmp on Wednesday May 12, 2021 @04:40PM (#27134907)
Makepad kinda has a minimum GPU spec. It's aging-out for the people who don't have this, but some people still don't have gpu's that can bitblit their screen with a solid color.
Re:Google Docs will now use canvas based rendering by rikarendsmp on Wednesday May 12, 2021 @04:24PM (#27134712)
I tried for it not to be, however there is no technically specific reason no.
Re:Google Docs will now use canvas based rendering by incrudible on Wednesday May 12, 2021 @02:27PM (#27133522)
> ... it's hard to beat just drawing on a canvas or using WebGL.

Both of these APIs perform quite poorly for what they're doing.

To compete with native, the web platform needs simple low-level APIs that do not have a lot of Javascript marshalling overhead and other performance cliffs. You can always build a more convenient library above low-level interfaces, but the opposite is not true.

Re:Google Docs will now use canvas based rendering by blacktriangle on Wednesday May 12, 2021 @02:29PM (#27133540)
They don't need to be better than native, they just need to be better than the DOM plus have the advantages of web-based distribution.
Re:Google Docs will now use canvas based rendering by habitue on Wednesday May 12, 2021 @03:21PM (#27134127)
Re:Google Docs will now use canvas based rendering by pjmlp on Friday May 14, 2021 @01:41AM (#27151117)
It is, but with luck version 1.0 will arrive at the end of the year and then there is the whole adoption rate.

Now given that WegGL support is still hit and miss, and the only way to debug is to rely on native GPGPU debuggers, and having the pleasure to differentiate between browser own rendering code and the one from the application, that shows how easy it is to do 3D on the Web.

Re:Google Docs will now use canvas based rendering by axguscbklp on Wednesday May 12, 2021 @02:56PM (#27133840)
>Both of these APIs perform quite poorly for what they're doing.

When it comes to Canvas, do you mean that it actually performs poorly when putting pixels on the screen using putImageData, or do you mean that it does that fine but it performs poorly when it comes to drawing vector graphics? In either case, do you know why it performs poorly?

Personally, I would be happy if Canvas just let you put raw pixel data on the screen and did that as well as possible. I have never felt any need for its vector graphics features. To me, they seem too high-level for what Canvas is supposed to be. But I guess things are different when it comes to using the graphics card, since from what I understand it is actually optimized for drawing polygons.

Re:Google Docs will now use canvas based rendering by incrudible on Wednesday May 12, 2021 @05:01PM (#27135100)
It performs poorly in either case. For one, Javascript APIs have significant marshalling overhead.

Secondly, Canvas is often "hardware-accelerated", which can make some things faster, but also slower because this kind of immediate-mode drawing doesn't match the GPU interface well. It's particularly slow at vector graphics. Some effects would require pixel readback, which is slow for the same reason.

> Personally, I would be happy if Canvas just let you put raw pixel data on the screen and did that as well as possible.

Drawing cached Bitmaps is relatively fast in Canvas, if you don't need too many calls. Getting arbitrary data into such a Bitmap is slow, so if you want to do it every frame you may run into issues.

Re:Google Docs will now use canvas based rendering by kllrnohj on Wednesday May 12, 2021 @09:43PM (#27137508)
> Secondly, Canvas is often "hardware-accelerated", which can make some things faster, but also slower because this kind of immediate-mode drawing doesn't match the GPU interface well. It's particularly slow at vector graphics. Some effects would require pixel readback, which is slow for the same reason.

https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasE...

One would assume/hope that specifying "bitmaprenderer" for the context type would give you a regular immediate-mode CPU rasterizer. Is that not the case?

> Getting arbitrary data into such a Bitmap is slow, so if you want to do it every frame you may run into issues.

To expand on this, doing that ("putting raw pixel data on screen") anywhere is slow if it's modified regularly. There just doesn't exist a fast CPU-buffer-to-display pipeline anymore, that died out years & years ago. So that one at least isn't a JS/web limitation, it's more a modern graphics architecture one. You just can't bit-bang pixels yourself anymore, not reasonably efficiently anyway. In theory that'd be possibly on unified memory architectures (read: mobile devices & integrated graphics), but GPUs don't like to publish their swizzled texture formats so you still don't get to even there.

Re:Google Docs will now use canvas based rendering by incrudible on Thursday May 13, 2021 @06:09AM (#27140459)
> One would assume/hope that specifying "bitmaprenderer" for the context type would give you a regular immediate-mode CPU rasterizer. Is that not the case?

No, that's something else.

> To expand on this...

I almost wrote something like that, but then I considered that I haven't really benchmarked this. Streaming data from CPU onto the GPU is certainly possible and graphics APIs do have hints for such usage. You also don't need to convert to a texture to get arbitrary data on the screen, a trivial shader can do that for you.

If your data/transformations naturally live in RAM/CPU, that may well be the most efficient thing to do.

Re:Google Docs will now use canvas based rendering by fock on Wednesday May 12, 2021 @04:31PM (#27134796)
I think this is a problem of the mainstream conception seeing the future browser mainly as a monopolized, walled garden (compared to GNU/Linux, which nowadays would do everything one wanted from a computer and more) with the canvas being a kind of framebuffer.

Back when I first read about the canvas, iirc there was no fancy CSS, no fancy custom elements and making a simple doodle-element or the famous doodle-jump as a webapp was ... - well, I guess there was flash. So if you think of HTML and DOM as a GUI toolkit, it filled an important void (and continues to do so) but nowadays noone wants to use (standardized) HTML anymore, so...

If you look into tk (or nowadays tkinter) you basically see the same with the Canvas-class (I think you can't draw anything custom at all in tk easily)!