How to improve Angular 2's template parsing performance? - performance

We're doing a rewrite of our UI using Angular 2. Since this is so new, there are very few resources available, so please excuse me, if my question seems silly and has been answered already.
First, a little background. Our product is built out of "modules" which are widgets that can be dropped on a page. Since, not all modules are being rewritten to use Angular 2, there will be a mix of non Angular and Angular modules on one page at the same time. For this reason, we've decided to make each Angular2 module to be a stand-alone angular app.
In the prototype phase all looked fine and dandy, however, fast forward a few months, and with just weeks before the release, someone looked at our page load times and was less than impressed. On my machine, with prodMode enabled, it takes 5 modules about 2.5 seconds to render with 2 of our most complicated modules taking a second each. The two biggest templates I've got are 32KB and 80KB in size, but since the processing time is the same, I suspect the linear length doesn't contribute as much as structural complexity, and they are pretty complex. The other 3 modules are much simpler.
From this timeline it seems that a lot of time is spent in parsing the template and loading components. So I thought maybe this is because each module is an independent angular app, and they probably don't share the cached components. So I've moved the BROWSER_APP_COMPILER_PROVIDERS from the App Providers into Platform Providers list. This caused all modules to reuse a single RuntimeCompiler (I think).
However in the grand scale of things, it did not improve the situation much. The total time went down to 2.3 seconds which makes it hardly worth the hassle.
Now, the modules are mostly wizards. That is they sit and look pretty until the user taps/clicks on the them to engage. So this got me thinking, what if I could stage the template parsing? If I could tell Angular to parse wizard steps on demand I could lower load time in exchange for some lag when interacting the the module. This is what I'm researching now, but I would love to hear the community's input.
Thank you for reading.
UPDATE: I am running RC.3.

In angular 2.4 we have a concept known as AOT, which can improve the performance!
An Angular application consists largely of components and their HTML templates. Before the browser can render the application, the components and templates must be converted to executable JavaScript by the Angular compiler.
You can compile the app in the browser, at runtime, as the application loads, using the just-in-time (JIT) compiler. This is the standard development approach shown throughout the documentation. It's great but it has shortcomings.
JIT compilation incurs a runtime performance penalty. Views take longer to render because of the in-browser compilation step. The application is bigger because it includes the Angular compiler and a lot of library code that the application won't actually need. Bigger apps take longer to transmit and are slower to load.
Compilation can uncover many component-template binding errors. JIT compilation discovers them at runtime, which is late in the process.
The ahead-of-time (AOT) compiler can catch template errors early and improve performance by compiling at build time.

Offline (pre)compiler could help, but it is not ready yet.
You could try replacing copy pasted/duplicated html code with separate component to reduce template size. Tree-like UI structure with reusable components might help.
Another way is to use lazy loading: load wizard when user clicks them (might use preloading).
I think it would be helpful to submit CPU profile to angular team, so that they could optimize compiler/parser.

Ok, Thanks for writing to me. So, if I am understanding this correct, every widget acts like different angular 2 app. Therefore, base module or base angular
app is dependent on multiple dependent injectable apps. Now, I am assuming this fact, that you have already taken bundling and minification of production ready
script. Apart from that, Just wanted to understand what is the SLA of API serving the request. Many a time, I observe that people complain UI for slowness. But,
it used to be the backend not meeting the SLAs. Check if your backend SLA is fine.
Next, what is your caching strategy of angular modules. How frequently, these are making request back to the server. Here is a catch. Around caching, all components
are not released in a battle ready status. Another thing, which I wanted to understand is, whether you are using RXJS for handling promises or not. RXJS, drammatically
improves the performance of angular 2 app.
Next, is reusablity of the code, say wrapping the reusable code in directive and then injecting the same at all the required places. This will cut the code compilation
cost.
Also, keep checking angular 2 milestones and the new fixes getting released around performance improvement. I am expecting final battle ready production framework
for angular 2 by December. Then, we will also migrate our apps to angular 2. Even, in nasdaq, we are currently running on 1.5X version. I hope this will help you
to improve the performance of your app.

Related

Performance of Xamarin vs. NativeScript

all.
So, I'm completely new to programming, especially mobile development. Considering goals for a future app I'm designing, I've been thinking of using NativeScript. I was reading the book "The NativeScript Book" offered on NativeScript.org, and they were discussiong JIT vs pre-compiling (AOT I guess it is? Correct me if I'm wrong on that). They also showed how a framework like Xamarin compiles down to the native file (.apk for Android and .ipa for Apple) where NativeScript runs in a javascript virtual machine.
When reading this, it seems like code that has been compiled BEFORE and not just at the time of execution would have a significant advantage in terms of speed, especially on phones where they aren't nearly as capable as modern desktop computers.
Can someone address this concern for me? Likely it's because I am ignorant and don't understand things yet, so please enlighten me and help me learn.
THanks :)
If you are new to programming, the performance of the framework should not be one of your priorities. You should start by focusing on other aspects, like portability, or simplicity of the solution. Learning to write good software should be your top priority instead of trying to write fast software.
Nonetheless, if this is really important for you, there are some benchmarks available opposing the different mobile oriented frameworks. For instance, the NativeScript website has one :
https://www.nativescript.org/blog/nativescript-and-xamarin
Check the 'Speed' section. It states for instance :
In these tests, you can see that Xamarin is roughly 200 ms faster than NativeScript at startup time.
But as you'll notice that when comparing performances, benchmarks always target only one aspect of the solution. This one in particular targets boot time. Some others target sorting of large arrays, or HTTP requests speed.
It is impossible to get a global performance test indicating which solution is the best. I think that one good example in that regard is the comparison of Xamarin VS Native languages (Swift // Java). Check this page :
https://www.altexsoft.com/blog/engineering/performance-comparison-xamarin-forms-xamarin-ios-xamarin-android-vs-android-and-ios-native-applications/
Xamarin is close to native solutions since it uses the native SDKs, but you will notice big differences between Xamarin and native. So it would be event more complicated to compare Xamarin and NativeScript which has a completely different logic !
In my opinion, you should start by the framework you like the most. And change it based on your experiences if you are not satisfied with it.

Steps to upgrade whole UI or Redo whole UI

I have an old web application (in asp.net) of almost 100 pages which is compatible to IE 6 so I want to revamp it's UI because it gives browser compatibility issues and doesn't look cool either. Now I am confused what things should I use and in what order to save time and avoid any error/flaw. Here are some questions:
1) I am thinking of using HTML 5 and make it responsive
2) I also heard of Angular JS, should I use it, if yes then where ?In my project java script and jquery both are used.
3) Should I use MVC ? But I am afraid it will require change of code which will lead to wastage of time. But it will make website faster.
Using MVC would surely speed up UI changes in future - all UI-related code would be separated in view part of code. If you can afford redesigning your code (it's gonna take some time), it's probably worth that, considering future maintenance.
If you want to create a good, responsive UI, according to modern standards - maybe have a look at Bootstrap (http://getbootstrap.com/) framework, or similar solutions (such as Foundation - http://foundation.zurb.com/)

GWT for large scale applications

I've heard the Google Web Toolkit isn't that good for web sites with more than 5 pages and a common layout. Is that true? We have at least a 100 subpages and a common layout defined in CSSes. Today were using PHP but we will move to a Java front either Spring MVC or GWT. We're using som jQuery AJAX and other jQuery components like a jqGrid. We also have some .swf-films and fusion charts. Will opting for Spring combined with GWT be a good choice or is Spring MVC with a jQuery library a better choice for us?
It's not true now. Earlier GWT versions really had some issues with scalability (e.g. problems with JS code size in IE - http://code.google.com/p/google-web-toolkit/issues/detail?id=1440), but since GWT 2.0 you have no limitations here.
Moreover, latest GWT versions support functionality for splitting projects to the parts that may be loaded dynamically when they're needed. Please refer to https://developers.google.com/web-toolkit/doc/latest/DevGuideCodeSplitting to learn how it works.
Take into account also that since Spring is Java, you have possibility to share classes between server- and client-side. Plus Java has very good support in IDE - all kind of refactoring will be available for you (it is not so convenient in case you use jQuery).
So Spring+GWT looks more preferable choice.
GWT is not a universal framework for building just a any webapp from scratch. It is very useful when you have a lot of complicated logic on client side, (image editing, real time collaboration, diagram drawing, games , complex reports building and etc etc). But all of this can be done without GWT.
GWT can be used when:
your team hates/dislikes JS (and is unable to build nothing complex with JS, just because they hate JS)
your team is quite experienced with Java
your team understand how all this browser related stuff works (HTTP, JS, DOM , CSS and etc)
in this project there are will be a lot of logic running on client side
I've seen quite a few big projects built completely with GWT. Some of them should never used GWT, because the were no reason for them to use it in such way. For most projects it is enough to use GWT only for some part of application.
The choice depends on your team and the project you are doing. If your team can't really see what benefits GWT will bring to the project, then you shouldn't use GWT.
Our enterprise-level application utilizes both and we're quite happy with the results. GWT is a powerful toolkit which lowers development time by orders of magnitude. That said, there are still things that GWT either doesn't handle all too well or just plain isn't suited for (and that's ok... that's why Spring MVC lives nearby). We have GWT-RPC hitting Spring services directly and it works incredibly well.
Our project though is a true webapp, not a website. We use a unified design which spans all "pages" (using a DockLayoutPanel and swapping out just the center makes this super easy).
IMO, whoever told you that GWT isn't good for consistent design across numerous "pages" is nuts...
I think any assertion that GWT (or any other method) lowers development time by an order of magnitude has already been debunked by Frederic Brooks in a time when shoulder pads and Jan Hammer's synthesizer were fashionable: http://en.wikipedia.org/wiki/No_Silver_Bullet.
But seriously, if you're a PHP shop, moving to 100% Java would be a huge investment, and not to be taken lightly.
On my experience of GWT, my only bad experience was with GWT compilation slowness due to lot's of permutations. Our application had more than 20 languages to support, which multiplied by 6 for browsers specific result in 120 permutations, which proved to get horrible performance.
But this is not a real bug issue, because you'll mainly use the dev mode, with instant code update, and you can have special compilation unit with reduced set of browser and language (even one language and one browser => one permutation if you wish).
So in my case, using Jenkins we made the big prod target full build nightly, deploying on a QA platform so that the QA team test every browser language combination. And on every commit a reduced build (1 browser and 2 languages in our case) was deployed on a dev validation platform.
GWT is definitively a great tool for large app. ;)

Should I use SmartGWT or Vaadin?

I'm going to develop a web application using SmartGWT. I've heard about Vaadin framework. I wonder what is the best to use?
My application will be used by ~500 users at the same time. And I need high response performance and high security control. I won't need dozen of pretty widget just enough to be able to use pretty tabbed pane and table. So what is the best choice regarding my needs?
Edit :
I'll also need a tool to export table content to Excel format (like in Google Doc SpreadSheet).
ps : already check this one Should I use Vaadin Framework
I looked into both these frameworks, and others, and decided to go with the core GWT widgets. You desire to have high response performance will be difficult with Vaadin since it sends almost everything back to the server. And if you don't need super fancy widgets then the core widgets (plus some incubator/3rd party ones as needed) should be fine. I didn't get deep into testing SmartGWT, but it seemed to really tie you into their framework (making it difficult to use core widgets as well) and I read about difficulties when starting to do things different than the showcase examples.
Good luck!
If you write your Vaadin application properly, it will be performing perfectly well (check this one: https://vaadin.com/wiki/-/wiki/Main/Optimizing%20Sluggish%20UI).
If you know SmartGWT, use it. Also, if you have no experience with Vaadin, use SmartGWT. It might take you a lot of time to learn Vaadin (it requires some practice after one is able to create well performing application). The biggest problem of Vaadin that it is very easy to write slow application - because everything seems to be so easy and one tends to use many components and so on...

WinForms Performance Question

My application has several large forms with lots of images which dramatically increases the size of the built executable. Over time, it seems that the startup performance becomes sluggish and it doesn't seem to be getting any better.
If I put all of the forms besides the main form in a separate dll, would it alleviate some of the pressure put on the application during startup?
I'd test it myself, but I have A LOT of forms and I don't want to do it unless someone can confirm that such an action will prove to be useful.
Many factors can affect startup performance. Have you used any tools to prove that it's the images?
For a start, go through these tips:
http://devcomponents.com/blog/?p=361
And consider using multithreading to load bigger objects in the background.
I'm not quite sure about that, but if I were you I would use the Profiler when it comes to improving performance.
Before I go guessing what's wrong, I consult with it and work my way up, because it tells me which methods and classes are costing the most in my code.
Another tip that may be useful: This reduced my application's startup time from 2 minutes to <10 seconds on a low-end thin client. Use NGEN to generate a precompiled native image of your assemblies.
I'm wondering if you were to use MEF and Lazy load, then when you actually need the module (Form) instantiate by calling .Value.
There are a couple of things I do with applications containing a lot of forms:
Create a UI .exe: basically only my forms
Create a backend .dll: everything that does the work behind the UI.
Are the images actually included in the .dll? If so, I would actually put my images into a .dll separate from the UI.
Given that the images are for toolbars, I wouldn't split them out as resources. I'll still stand fast on my advice to split into multiple .dlls.
As others said, profile, don't guess.
Not just any profiler will do.
Here's a user (besides me) who discovered random pausing on his own.
You say the "intense" methods are all in dlls you don't have source code for - that's typical and normal.
What you need to know is which statements in your code are requesting the time to be spent, and they can't be restricted to CPU-only time.
Most profilers don't tell you this, but random-pausing does.
If you're interested, here's a recent discussion of the issues.

Resources