News for hackers. Stuff that matters.
Re:Mozilla can produce near-native performance on the Web by ux-app on Wednesday May 22, 2013 @10:33PM (#5755021)
For most applications JS doesn't need to get any quicker. What makes web apps feel like swimming through molasses is the DOM.

Even something as simple as getting a Div to follow the mouse on anything but the simplest of pages is impossible to do without incurring ridiculous lag.

I don't know enough about them, but it seems that maybe Web Components may offer some answers by encapsulating mini Document trees which presumably exist in isolation from other components thereby reducing the penalties of dynamic CSS.

Re:Mozilla can produce near-native performance on the Web by just2n on Thursday May 23, 2013 @01:05AM (#5755441)
Like this? http://jsfiddle.net/eymAS/2/

The DOM is faster than almost everyone believes. It's not 2001 anymore, guys.

Web components solve a lot of major problems, but it has little to do with DOM/CSS performance and more to do with encapsulation (ie, so your CSS/HTML/JS don't break a component). DocumentFragments and insertAdjacentHTML solved more performance problems for the DOM than most other API changes have, and smarter compositing/painting algorithms in browsers (along with hardware acceleration) have made it possible to do some pretty ridiculous stuff.

Re:Mozilla can produce near-native performance on the Web by roel_v on Thursday May 23, 2013 @02:52AM (#5755646)
So now we're going to say that in 2013 it is impressive that 160 rectangles can follow a mouse cursor? I see the advantages of client/server applications (as they used to be called), and presumably js/css apps will continue to get faster and asymptotically approach their client-only functional equivalents, but there is a thing about a hammer and all problems looking like nails that springs to mind when I see people claim that moving 160 rectangles in 16 ms / frame is 'scary fast'...
Re:Mozilla can produce near-native performance on the Web by just2n on Thursday May 23, 2013 @03:07AM (#5755675)
The parent's comment was that it is essentially infeasible to have a single div follow the cursor due to performance issues with the DOM. The fiddle includes 160 divs and opacity to demonstrate that that claim is false.

There's an awful lot of red herring going on in your post. It sounds like you have some problems with the web, but they most certainly aren't relevant to this discussion.

Re:Mozilla can produce near-native performance on the Web by roel_v on Thursday May 23, 2013 @08:39AM (#5756472)
Oh I have no problems with the web, it has been providing me with a good living for well over a decade. Maybe that's my problem - that I remember the times when things that are being described now as 'great' or 'fast' were solved already, and my frustration is that instead of moving forward, we now have to repeat the last decade except with js/css before we can really start to innovate again.

Unreal engine in the browser? Seriously? Because of what - because it's easier to update people's clients when they download it again every time they visit your website? We had web launchers and auto-updating that solved everything the web brings as an advantage over desktop applications (in the use cases that require fast graphics, i.e. not CRUD line of business applications) years ago.

The elephant in the room here is that people want to push web applications because it's easier to make money from them, and you can make more of it, over a longer time. Look, I do it too, I know that the web beats the pants off client-only software from a business point of view. But let's call a spade a spade and not tip toe around it with bullshit pseudo-arguments like 'ease of deployability' and 'social sharing' and 'portability' and 'platform-agnosticity'.

Re:Mozilla can produce near-native performance on the Web by griffordson on Thursday May 23, 2013 @09:16AM (#5756628)
If an app that had no sustainable future as a native app becomes possible as a web app, don't users also benefit? The fact is that many people are willing to pay for a service they continue to get value from month after month. And the recurring revenue also usually comes with recurring support because companies have to keep winning customer loyalty in a way they never have to with a one time sale. I think it is a net win for both customers and the companies selling the services.

And developers win because there are more viable businesses which need their skills over the long term.

Should it be possible to sell a native app as a service? Maybe, but supporting a native app professionally is much more difficult than you seem to be acknowledging. Have you ever supported a native app in the wild across a wide variety of generic PC hardware for novice users?

Re:Mozilla can produce near-native performance on the Web by roel_v on Thursday May 23, 2013 @09:45AM (#5756756)
"If an app that had no sustainable future as a native app becomes possible as a web app, don't users also benefit?"

Of course they do, therefore charging for software (desktop & web alike) = good. Make no mistake on which side in that debate I'm on. But let's call it like that.

"And developers win because there are more viable businesses which need their skills over the long term."

Sure, and it's no more than fair, and the natural order to boot.

"Have you ever supported a native app in the wild across a wide variety of generic PC hardware for novice users?"

I'm glad you ask, because actually yes I do, and it's a pain in the ass for the most part. And for the parts where it makes sense, I have moved parts of the services we offer to web applications. Therefore I feel I'm experienced enough to compare the advantages and disadvantages of the two, and from that I criticize the developments of people wanting to shoehorn everything into the browser, either because of covered up ulterior motives, or because it's all they know and want to know. But again - then say so, and don't sugarcoat it under the fuzzy 'it's better for the user' rhetoric that is so prevalent.

Re:Mozilla can produce near-native performance on the Web by roel_v on Thursday May 23, 2013 @11:13AM (#5757246)
I should add that another reason can be "because I can", which is a perfectly fine reason too, but then label it as such so that naive greenhorns don't start pushing production systems in this direction, requiring others to then deal with the fallout.
Re:Mozilla can produce near-native performance on the Web by spyder on Thursday May 23, 2013 @05:35AM (#5755957)
For me the movement is smooth but it still lags behind the mouse with 10-20 px. The Firefox version of the demo has a little less lag but still looks disconnected from the mouse when moved.
Re:Mozilla can produce near-native performance on the Web by cpleppert on Thursday May 23, 2013 @11:14AM (#5757254)
The problem is that the DOM is a hard upper limit on performance compared to what the performance of an unsafe language (asm.js) is. It is massively complex because it must perform every UI task in the browser and simply moving around DIVs doesn't give you a feel for its the performance in complex scenarios.

If you think about how native applications perform and then imagine every one having to go through a DOM interface and every button and UI interaction being composed of DOM elements and re-styling these elements on every interaction you get a sense of what the problem is. There is simply no way to get the DOM to do something it wasn't designed to do, which is to be a document display interface and not a general graphical user interface. You have to clobber together a lot of interactions to get the desired behavior and not only does this increase the overhead for both your program and the DOM you are going to hit cases where the DOM isn't optimized.

This doesn't mean that the DOM is inherently slow. If you tried to offload the UI work onto javascript you wouldn't get the performance benefit of doing that on Asm.js or NACL. You really need unsafe code to solve this problem. Asm.js and NACL are only useful if you are going to do this; targeting the Canvas and WebGL gives you the ability to do that.

Re:Mozilla can produce near-native performance on the Web by vladmoz on Monday May 27, 2013 @05:05PM (#5776579)
What you describe -- "imagine every one having to go through a DOM interface and every button and UI interaction being composed of DOM elements and re-styling these elements on every interaction" -- is exactly how Firefox is built. The desktop Firefox UI is all DOM elements (not HTML, but still the same underlying DOM code).

Hovering over a toolbar button or a tab causes a CSS style rule for a :hover effect to be applied. Opening a new tab uses CSS animation for the transition. Moving tabs around manipulates the DOM and moves the tab elements (which are themselves composed of images, labels, etc.).

And yet, the Firefox UI is plenty snappy -- yes, you can argue that there are slowdowns and issues that need to be fixed, but no more or less than in many "native" apps.

Re:Mozilla can produce near-native performance on the Web by BrendanEich on Saturday May 25, 2013 @06:48PM (#5769167)
asm.js is not an "unsafe language".

/be

Re:Mozilla can produce near-native performance on the Web by ux-app on Thursday May 23, 2013 @03:17AM (#5755689)
That is very cool. I got quite bad rubber banding initially (with a reported 60fps), however after turning off v-sync in chrome://flags I got super smooth 120fps performance.

Would be great if Chrome had this option off by default.

Re:Mozilla can produce near-native performance on the Web by exDM69 on Thursday May 23, 2013 @03:49AM (#5755747)
> Would be great if Chrome had this option off by default.

Disabling Vsync causes page tearing artifacts (https://en.wikipedia.org/wiki/Page_tearing). It should always be enabled by default. Some new gpu drivers also have "adaptive vsync", where it's enabled by default but gets temporarily disabled when deadlines are not met.

Re:Mozilla can produce near-native performance on the Web by ux-app on Thursday May 23, 2013 @04:13AM (#5755791)
isn't tearing preferable to input lag? As I mentioned, with v-sync on there is a very noticeable rubber-banding effect, with it off the result is (perceptually) far smoother.

>It [vsync] should always be enabled by default

Not sure about this. Surely the goal is to maximize perceived performance not 'correctness' (where correctness in this context is defined as each frame being fully drawn before the next one starts).

Re:Mozilla can produce near-native performance on the Web by exDM69 on Thursday May 23, 2013 @04:57AM (#5755874)
> isn't tearing preferable to input lag?

In a properly written app, vsync should not cause input lag despite gamer superstitions. But there are lots of not-properly written apps where this is a problem.

WebGL / Chrome should solve the problem in some other way, not disabling vsync. Or using adaptive vsync if available as a workaround.

The culprit here might be the ANGLE OpenGLES2-on-D3D9 wrapper that Chrome uses, which is notoriously slow on synchronous operations like vsync, glGetError or glFinish.

Re:Mozilla can produce near-native performance on the Web by just2n on Sunday June 02, 2013 @12:03AM (#5807251)
That was just caused by me not processing input properly. I've set up a proper rendering loop here and now only render the most recent mouse position on each frame:

http://jsfiddle.net/eymAS/84/

It's better, but still limited to 60fps, and since I render to the state at 0s, the worst delay we can see is ~16.6ms + rendering time.

Re:Mozilla can produce near-native performance on the Web by fhd2 on Thursday May 23, 2013 @02:41AM (#5755630)
Here's a version that's not Chrome-only: http://jsfiddle.net/eymAS/21/

I've been wondering why I keep hearing that the DOM is supposed to be slow. Don't people mean to say that rendering (i.e. mostly CSS) is slow? This fiddle is certainly not doing much with the DOM except setting style attributes.

Re:Mozilla can produce near-native performance on the Web by vladmoz on Monday May 27, 2013 @05:01PM (#5776563)
The problem with the DOM is not that it's intrinsically slow, but that it's very easy to do slow things with it inadvertently. There are often N different ways to do things, due to the evolution of HTML. The newer approaches tend to be designed with things like GPU acceleration in mind (e.g. CSS transforms), whereas older methods often had lots of heavy interactions and computations because they weren't expected to be used dynamically.

Just like optimizing any software takes skill and knowledge, so too does writing HTML, whether dynamic or not. Tools for understanding what's going on with the DOM and with dynamic HTML are slowly becoming available as well, which will help with this.

Re:Mozilla can produce near-native performance on the Web by just2n on Thursday May 23, 2013 @03:38AM (#5755724)
People generally mean their manipulation of DOM is effectively slow. That's a perfectly accurate statement, but the problem is calling the DOM slow as a result. The real culprit is often that doing stupid things with the DOM cause style recalcs, reflows, layouts, compositing, painting, etc. Those are all comparatively expensive.
Re:Mozilla can produce near-native performance on the Web by ChuckMcM on Thursday May 23, 2013 @01:19AM (#5755477)
Man, that is just scary fast :-)
Re:Mozilla can produce near-native performance on the Web by krebby on Thursday May 23, 2013 @01:56AM (#5755548)
It should be, it's hardware-accelerated (take a look at the translate3d hack)

Paul Irish did a good writeup here: http://www.paulirish.com/2012/why-moving-elements-with-trans...

Re:Mozilla can produce near-native performance on the Web by just2n on Thursday May 23, 2013 @03:48AM (#5755742)
Yep. Here's a version without using 3d (no layers generated for the followers): http://jsfiddle.net/eymAS/29/

The layout/composition/painting etc is taking roughly 5x longer now. Chrome is smart enough to do it all just once, though, so it's still relatively performant.

Re:Mozilla can produce near-native performance on the Web by ihsw on Wednesday May 22, 2013 @10:51PM (#5755066)
> What makes web apps feel like swimming through molasses is the DOM.

I would contend that network latency and the plethora of domains queried to be a greater impediment to a speedy web. DOM manipulation may be absurdly slow however it cannot hold a candle to latency hold-ups.

Most readers on HN live in a quiet and peaceful bubble of high-quality network connections, but the majority of the world is beginning to wake up to the web and they'll have to endure latency issues that we haven't experienced since "broadband" was a new concept.

Re:Mozilla can produce near-native performance on the Web by carbocation on Wednesday May 22, 2013 @11:16PM (#5755142)
Quite a few HNers have probably experienced lossy connections such as Amtrak or busy coffee shops. I would think that those high-loss situations would feel somewhat like a high latency experience.
Re:Mozilla can produce near-native performance on the Web by wslh on Thursday May 23, 2013 @03:56AM (#5755761)
Lossy mobile connections are very common in the world.
Re:Mozilla can produce near-native performance on the Web by pyre on Thursday May 23, 2013 @12:50AM (#5755407)

  | DOM manipulation may be absurdly slow however
  | it cannot hold a candle to latency hold-ups.
Just an anecdote, but jQueryUI + IE8 took 8 seconds to style all of the buttons[1] we had on a page during one call. Granted, we had a ton of buttons (most were hidden), but that's a lot of time. The same call on Firefox and Chrome were fractions of a second (can't remember the exact numbers, but Chrome was faster at the time), and this was a couple of years ago. DOM manipulation can be a real drag.

[1] http://jqueryui.com/button/

Re:Mozilla can produce near-native performance on the Web by derleth on Thursday May 23, 2013 @12:22AM (#5755338)
But we do know how to handle bad latency, don't we? Speculative loading, which got a bad name because it makes wallhacks on FPSes work but really has almost no downside once the client can't do anything malicious with a little information the human isn't using yet.

If the real problem isn't latency but bandwidth or bandwidth caps, that will require other solutions.

Re:Mozilla can produce near-native performance on the Web by notatoad on Wednesday May 22, 2013 @11:06PM (#5755096)
For most applications, the Dom is the weak point because manipulating the Dom is as ambitious as the apps get. The exciting part of asm.js is not that it can speed up existing apps, it's all the cool new things you can do on the client side now that were simply to slow to be possible before.
Re:Mozilla can produce near-native performance on the Web by ux-app on Wednesday May 22, 2013 @11:18PM (#5755149)
Yeah that's a fair point. What kinds of new apps do you think this will enable (besides games)?

It seems that the DOM will continue to be the major bottleneck since presumably the GUI for these new apps will still be DOM based.

Re:Mozilla can produce near-native performance on the Web by Yoric on Thursday May 23, 2013 @06:47AM (#5756140)
I expect Virtual Machines for domain-specific languages. I also expect (de)compression, cryptography, number-crunching, graphics algorithms, etc.
Re:Mozilla can produce near-native performance on the Web by chii on Thursday May 23, 2013 @12:53AM (#5755417)
i see porting over existing codebases and rendering not via DOM but webgl as the path this takes on.
Re:Mozilla can produce near-native performance on the Web by untog on Wednesday May 22, 2013 @10:55PM (#5755077)
What makes web apps feel like swimming through molasses is the DOM.

In my experience, it's the lack of threading. Or any way to perform an operation without affecting the UI. Web Workers go a long way to solving this, but they're limited in what they can do.

Re:Mozilla can produce near-native performance on the Web by ux-app on Wednesday May 22, 2013 @11:07PM (#5755101)
Not sure I agree with this. Very few web applications are CPU bound to the point of locking the UI. Web Workers are extremely useful, however very few current web apps benefit from them. Given they cannot interact with the DOM they are limited to pure number crunching. Great if you're ray tracing or encoding/decoding sound or video, not much use to the other 99% of web apps.

My understanding is that parsing CSS rules and updating the DOM are incredibly costly operations which none of the browser vendors have yet decided to optimise.

Re:Mozilla can produce near-native performance on the Web by daeken on Wednesday May 22, 2013 @11:12PM (#5755124)
> My understanding is that parsing CSS rules and updating the DOM are incredibly costly operations which none of the browser vendors have yet decided to optimise.

These operations are extremely well-optimized. The reason they're slow is that they're also extremely complex and slow operations. It's not something you can hack around.

Re:Mozilla can produce near-native performance on the Web by ux-app on Wednesday May 22, 2013 @11:28PM (#5755188)
> The reason they're slow is that they're also extremely complex and slow operations.

In that case it seems that we need something new to replace CSS for layout.

Or maybe a 'strict mode' equivalent for CSS where styling is separated from layout. In this mode rules that affect style (bold, font etc) cannot affect container dimensions. This mode would include a subset of rules that affect only layout (position, width, height etc).

This would presumably greatly reduce the impact of the parse/dom traversal/paint cycle of CSS.

Re:Mozilla can produce near-native performance on the Web by untog on Wednesday May 22, 2013 @11:45PM (#5755239)
In this mode rules that affect style (bold, font etc)

But bold and font would affect the width of the text which would affect text flow and possibly affect whether the container ought to grow and shrink or whether it ought to provide scroll bars...

No change is simple, in that sense.

Re:Mozilla can produce near-native performance on the Web by _greim_ on Thursday May 23, 2013 @01:57AM (#5755549)
> In that case it seems that we need something new to replace CSS for layout

There's so much that CSS (and browsers in general) do that we take for granted, which is good in one sense but bad since you can't dip below those abstractions and grapple with the layout engine (or garbage collector, or HTML parser, or selector engine) at a low level. You get the whole ball of wax and all that stuff runs all the time, even if you don't actually need it. In my view this is essentially what separates HTML apps from native ones.

Re:Mozilla can produce near-native performance on the Web by wwweston on Thursday May 23, 2013 @06:58AM (#5756172)
I totally think CSS layout could use some improvements, but isn't the separation you're talking about here already pretty strong?

I'm struggling to think of an example of a situation where text styles affect layout on containers where dimensions are anything other than 'auto'. And any situation at all where text styles affect positioning.

Re:Mozilla can produce near-native performance on the Web by spyder on Thursday May 23, 2013 @05:41AM (#5755968)
So we need asm.css? :)
Re:Mozilla can produce near-native performance on the Web by untog on Wednesday May 22, 2013 @11:19PM (#5755155)
An example from my experience- auto-complete filtering. Loading a list of the user's Facebook friends (which can number into the thousands) and filter as they type.

When that's on the main UI thread it's hideous- the page stops responding to typing, so people hit the key twice, the whole page feels like it's hanging. It's not constant CPU usage, but it's CPU usage at the exact moment the user expects the site to react immediately. Same goes for calculations when a user is swiping, or something like that.

Re:Mozilla can produce near-native performance on the Web by pcwalton on Wednesday May 22, 2013 @11:13PM (#5755126)
The browser vendors definitely do micro-optimize these. DOM binding performance is measured in nanoseconds these days.
Re:Mozilla can produce near-native performance on the Web by MatthewPhillips on Wednesday May 22, 2013 @11:20PM (#5755159)
Then what is it?
Re:Mozilla can produce near-native performance on the Web by ricardobeat on Wednesday May 22, 2013 @11:45PM (#5755238)
Repaints/reflow. DOM+CSS+JS is a complex system. Watch this: http://www.paulirish.com/2011/dom-html5-css3-performance/
Re:Mozilla can produce near-native performance on the Web by wyck on Thursday May 23, 2013 @01:18AM (#5755474)
To add to ricardobeat, it's all repaints and recalculations. Web devs have become overzealous with smashing JS into every nook and cranny to manipulate the dom, it seems to be a battle Google is trying to educate people about, and good on them.

Open dev tools in chrome, the click network/frames, hit record and refresh the page. Do this on a sluggish site that uses tons of js and you will see the problem.

Re:Mozilla can produce near-native performance on the Web by bzbarsky on Thursday May 23, 2013 @01:48PM (#5758231)
The most commons causes of slowness I've seen are:

1) Interleaving changes to style and requests for layout information: this causes lots of relayouts instead of just one.

2) Using libraries that under the hood helpfully end up doing item #1 for you.

3) Using complex graphical effects (blurred shadows are a common one, as are certain gradients) that are actually very expensive to implement and may not be amenable to being GPU-accelerated.

Re:Mozilla can produce near-native performance on the Web by vidarh on Thursday May 23, 2013 @05:54AM (#5755993)
> Very few web applications are CPU bound to the point of locking the UI.

It comes up regularly around here. We've had to resort to all kinds of ugly workarounds (such, as, e.g. chunking work and running small pieces off setTimeout() or requestAnimationFrame). A simple thing like changing fonts on the Canvas more than a couple of things can kill any hope of a responsive UI unless you very carefully manage your rendering, depending on browser (Canvas font handling is ok on Chrome, and ridiculously slow on Firefox, for example).