r/javascript • u/notunlikethewaves • Jun 01 '15
Is ReactJS faster than AngularJS ?
http://blog.500tech.com/is-reactjs-fast/15
u/WishCow Jun 01 '15 edited Jun 01 '15
I don't get this obsession with speed. Neither of them is slow enough to matter out of the box. If you do get to a size where it starts to matter, they both offer ways of solving it.
Ease of maintenance, documentation, community, these are ten times more important to me than "rendering speed in 1000 iterations".
6
u/bendman Jun 01 '15
Speed often matters more depending on the situation. Developing a web app primarily used on mobile phones for example.
3
u/holloway Jun 01 '15 edited Jun 02 '15
With Google Material and other UI ideas there's been a push toward animation at 60fps, which (in most browsers) means each time JavaScript executes that it runs for no longer than 16ms. Fast everything in JavaScript in essential for that.
edit: just published a blog post about browser engines and fast animation
3
u/ngly Jun 02 '15
Speed is huge, especially on mobile devices. It becomes a huge issue once you start scaling your application. The benefits may seem insignificant, but it quickly adds up. I think if speed wasn't important large companies wouldn't be focusing on it so much. Try using chrome dev tool Network throttling in their emulation for 1 day.
10
u/a0viedo Jun 01 '15
Isn't this analog to say "Are a set of wheels faster than a Volkswagen?"? AFAIK, React handles only the view while Angular tackles model, view and controller.
2
2
u/RankFoundry Jun 01 '15
Angular still has lots of shortcomings beyond performance. Everything from the crappy docs to directives (yuck) leaves a lot to be desired. There's a reason why they rewrote it from scratch in Angular 2.0 (many reasons really). Version 1 should not have been touted as production ready.
9
u/jellatin Jun 01 '15
If they left in features from 1.x you didn't think are good in 2.x you would criticize them for it. If they fix the features you think are broken in 1.x for the 2.x release then you criticize them. Your comment history makes it look like you just want a reason to complain.
And as a side note, React's docs are nothing to brag about. Having to learn about features like contexts from StackOverflow posts because they are straight up left out of the docs isn't any better than Angular.
-1
u/RankFoundry Jun 01 '15
It's not really an issue of features, it's architecture and redundant ways to do things with unclear differences (if any).
Nothing wrong with complaining when it's justified.
I'm not a React fanboy. I'm not a fanboy of anything which is why I get on the nerves of fanboys.
3
u/jellatin Jun 01 '15 edited Jun 02 '15
Nothing wrong with complaining when it's justified.
The problem is you've left absolutely no paths for a project to be right. You have said "everything they can do will be wrong whether they fix things or not". If you're already committed to every move being wrong, then you're just complaining to complain.
I'm not a React fanboy
This is hard to believe when your comment history is selectively applying criticism at Angular and admitting none of React's shortcomings.
0
u/RankFoundry Jun 02 '15
I've also said nothing about Ember or mozzarella cheese sticks. Perhaps I'm secretly an undercover agent for Ember and Italian cheese in stick form.
1
u/jhallister Jun 02 '15
He's not wrong... your comments indicate that your frustration with Angular had more to do with your inability to learn how to use it properly, rather than a real complaint about implementation. You aren't alone.
1
u/RankFoundry Jun 02 '15
Ah, the tired old "You just don't get it" argument. Well, I might buy that if I were the only one with this perspective but there are far too many people who share it for this to be about me.
1
u/jhallister Jun 03 '15
By that logic the only way something isn't a problem is if everyone understands it. Besides, I said you weren't alone. That's primarily the teams fault, the docs were pretty bad for a really long time.
And sure there are plenty of people that have issues with Angular, there also happens to be plenty of people that call themselves "web developers" when they know HTML. And if there's anything I've learned, it's that opinions in this industry about tools tend to gravitate towards easy = good.
20
Jun 01 '15
Version 1 should not have been touted as production ready.
Oh get over it already. Angular 1 served it's purpose and they've learned from it.
Considering tons of companies are using Angular in production, it's perfectly production ready, regardless of it's flaws.
2
u/RankFoundry Jun 01 '15
A lot of companies use a lot of crap in production. Just because you can eventually eek half decent performance out of a non-trivial app with Angular (after beating your head against the wall and endless online searches) doesn't mean it's a good choice. For something that was supposed to make things simpler and better out of the box, I'd say it failed. Again, they didn't rewrite it from scratch for no reason.
7
u/rduoll Jun 01 '15
What's wrong with directives?
3
u/RankFoundry Jun 01 '15
This will devolve into a debate on preferences but after trying libraries/frameworks that use them and ones that keep all that stuff in JS, I'd take the latter any day.
1
u/Randolpho Software Architect Jun 02 '15
Which flavor are you objecting to? The DOM manipulation flavor, or the more typically used "Controller + Template" flavor? Because the latter is some yummy yummy koolaid. And if you know CSS real good-like and understand state machines, you can do a crap-ton of amazing capability with that other directive flavor without ever diving under the covers for direct DOM manipulation.
0
Jun 01 '15
[deleted]
3
u/rduoll Jun 01 '15
What? I didn't even express a viewpoint. I simply asked what was wrong with directives since RankFoundry expressed distaste when mentioning them.
I want to know what RankFoundy has to say about them. Nothing more, nothing less.
1
u/fk122 Jun 01 '15
I wrote a blog post comparing the performance of React, Angular and Knockout. It's not perfect, but it illustrates that out of the box, React performs better than both Angular and Knockout.
http://dapperdeveloper.com/2015/01/26/performance-of-angularjs-reactjs-and-knockoutjs-compared/
1
u/coldinchitown Jun 01 '15
It'll certainly be mighty interesting to see how out-of-the-box angular 2.0 compares to react.
5
u/androbat Jun 01 '15 edited Jun 01 '15
Performance isn't a fair comparison (and won't be for a while), but I think React wins in a comparison of framework designs.
Here's an ES5 nested component example from angular.io (page). I threw in a quick event and loop for comparison.
function ParentComponent() { this.message = "I'm the parent"; this.arr = [{id: '1', name: 'foo'}, {id: '2', name: 'bar'}, {id: '3', name: 'baz'}]; this.handleClick = function () { console.log('something clicked'); }; } ParentComponent.annotations = [ new angular.ComponentAnnotation({ selector: "parent" }), new angular.ViewAnnotation({ template: '<h1>{{ message }}</h1>' + '<ul>' + '<li *for="#item of arr">' + '{{ item.name }}' + '</li>' + '</ul>' + '<button (click)="handleClick()">Click Me!</button>' + '<child></child>', directives: [ChildComponent, For, If] }) ]; function ChildComponent() { this.message = "I'm the child"; } ChildComponent.annotations = [ new angular.ComponentAnnotation({ selector: "child" }), new angular.ViewAnnotation({ template: '<p> {{ message }} </p>' }) ];And this is the equivalent React code.
var ParentComponent = React.createClass({ getInitialState: function () { return { message: "I'm the parent", arr: [{id: '1', name: 'foo'}, {id: '2', name: 'bar'}, {id: '3', name: 'baz'}] }; }, handleClick: function () { console.log('something clicked'); }, render: function () { var items = this.state.arr.map(function (item) { return <li key={item.id}>{item.name}</li>; }); return ( <div> <h1>{this.state.message}</h1> <ul>{items}</ul> <button onclick={this.handleClick}>Click Me!</button> <ChildComponent msg={this.state.message}/> </div> ); } }); var ChildComponent = React.createClass({ render: function () { return <p>{this.props.msg}</p>; } };I haven't tested the code, but it should work (famous last words...).
My immediate reaction is that Angular is more verbose. I'm not a fan of the '*for' syntax or string templates (I assume there's a way of adding an external template here). Throwing a DSL into the markup is also flawed in my opinion. Auto-inherited scopes seem to be at work once again (with all the debugging hell of long prototype chains). The typescript/ES6 class looks a little better only to tack on @view and @component decorators. I like decorators, but these receive a lot of arguments (complete templates and such) which Python users have generally come to accept as bad decorator design. Overall, it's a huge step up from Angular 1.x, but I think it still lacks the elegance (and definitely the composability) of React.
The Alpha docs are terrible (I don't count that against anybody until they get closer to release, but it does make comparison a little hard). On a larger scale, dependency injection once again makes an appearance (it seems better than 1.x, but I'm not convinced that it adds anything of value). '[control]="foo"' seems like it compounds template syntax overload (asterisks, parens, braces, curly-braces, pipes, DSLs, etc).
The latest articles on Angular 2 read a lot like the older intro articles for React (that is, they are trying to show 1.x users how to think in components). This move is good, but I don't see Angular 2 offering anything of added value over React while it still holds on to some things that create complexity without offering much in exchange except the "Angular way" mantra.
3
u/coldinchitown Jun 01 '15
Yikes. Clarity-wise, React does seem to be quite a bit more pleasant. Thanks!
0
u/dvlsg Jun 01 '15
If you're comparing ES5 syntax from angular, you should be comparing it to ES5 syntax from react.
2
u/androbat Jun 01 '15 edited Jun 01 '15
I'm assuming you are talking about the use of JSX. There is an in-browser JSX transformer. If you have a problem with source translation, then there's the fact that Angular 2 has a complete HTML DSL with all the asterisks, parens, braces, filters, inline-code, custom iterator code, etc (and that's before we talk about dependency injection).
Next there's the fact that JSX is heavily based on the E4X ECMA Standard pass in 2005 (pre-dating ES5.0 by 4 years and ES5.1 by 6 years), so JSX adheres to a real JS spec (even if that spec isn't popular).
I could have used typescript examples, but they add even more complexity to the comparison and don't reflect how a lot of developers will use the framework (myself for example; if I'm going to transpile a non-JS dialect, it will be for clojure async and macros or purescript's real type system).
29
u/cgaudreau senior HTML9 engineer Jun 01 '15
I feel like this is desperate grasping at straws. It is theoretically possible to make Angular nearly as fast or faster than React is out-of-the-box, but the pain involved in doing so is massive. Yes, it's easy with little 5-line code snippets, but try doing so in a reasonably-sized application. It's hell.
React makes it easy to be fast by default. You generally don't even have to think about performance, and if you do have to, it is very easy to grasp. You don't need to frantically search extremely poor documentation.
How to optimize a React application: Implement
shouldComponentUpdate. Or if you want performance by default, just use immutable data structures.How to optimize an Angular application: Keep your scopes small. Keep it under 2000 watchers. Pollute your code with one-way bindings. Still no improvement? Oh, you need to do one-way binding here, too, in some obscure way. Don't watch functions. Don't watch objects. No
$broadcastor$emit. Don't have big arrays. Should I use$digestor$apply? Why is this watcher causing the digest loop to take 500 ms to execute? No filtering or sorting unless you want to go mad. Did I mention using filters causes$indexto be invalidated? How the hell do I even find out what's performing poorly?I don't even know if any of that is correct anymore. It's too painful to remember. I want to be liberated and forget the literal hell that is Angular 1.x.