performance: precompiling and partial caching

420 views
Skip to first unread message

Tim Cuthbertson

unread,
Aug 15, 2011, 5:44:21 AM8/15/11
to angular
Hi all,

I've used and greatly enjoyed angular on personal projects. Recently I
suggested using it for a work project. The prototype worked well but
suffered from some unfortunate performance issues, mostly related to
startup time on IE 7 (it locked up the browser on load for about 9
seconds, and this isn't even IE6 ;)).

I'd have liked to delve into the performance issues at the time, but
didn't have the bandwidth and we went with the more lightweight manual
backbone.js instead. But I'm interested in thoughts on performance
now, even if it's sadly too late for this particular project.

It seemed a lot of the startup time was spent compiling templates and
initializing the system (callbacks, events, etc). I don't expect the
second part of that can be done ahead of time, but has there been any
thought given to precompiling templates? That could reduce the startup
time, but I'm not really sure how much time you would save given you
obviously still have to set up DOM events and other things on
initialization.

Another thought I had is more related to runtime performance than
initialization: is there any functionality in angular to cache
previously-computed values or parts-of-values? Say if I use object.foo.
$size() in ten different places in my template, will the size be
calculated ten times? How about if I use obj.foo.$size() as a
subexpression in other template values?

And when `obj` changes but `foo` remains the same, does anything get
re-calculated? It seems like it would be a lot of work an might not
work in an impure language like javascript, but there may be some
things that can be done.

Cheers,
- Tim.

Vojta Jina

unread,
Aug 15, 2011, 6:21:35 AM8/15/11
to ang...@googlegroups.com
Hi Tim,

we already had the idea about pre-compiling the templates on server side.
One thing is performance, the other is crawlability of the page - so I personally think we need that.
Unfortunately nothing has been done yet, as we are currently very busy to get v1.0 released...

Did you notice any problems during run-time as well ?
We are just about to release new implementation of scope, which should be much faster (benchmarks tell 4x).
This should improve the run-time performance...

How about other browsers like Chrome, FF or IE8 / 9 ?

Could you share your prototype code with us ? It might be helpful to have a chat about these things.
I have some ideas how to improve the run-time - binding process, but so far, it's just theory - might be very helpful to see your code...

Thank you very much !
V.

Tim Cuthbertson

unread,
Aug 15, 2011, 8:14:18 AM8/15/11
to angular
> we already had the idea about pre-compiling the templates on server side.
> One thing is performance, the other is crawlability of the page - so I
> personally think we need that.
> Unfortunately nothing has been done yet, as we are currently very busy to
> get v1.0 released...

Fair enough, I'll be following eagerly :)
(on that thought - is there a blog or annoucements list? github is too
granular, and twitter is a bit noisy (and lacking in detail...))

> Did you notice any problems during run-time as well ?
> We are just about to release new implementation of scope, which should be
> much faster (benchmarks tell 4x).
> This should improve the run-time performance...
>
> How about other browsers like Chrome, FF or IE8 / 9 ?

Other browsers were pretty good (sub-second initialization). We didn't
notice any issues when interacting with the page (adding / removing
elements etc). There was a moderate (sub-1s) lag when we replaced the
root model with an updated version from the server and it had a lot of
children (~30 or so, each with a few attributes), I suspect there was
a lot of computation going on there that didn't need to since
typically the model returned by the server would be exactly or nearly
the same as the existing model that was already being displayed.

> Could you share your prototype code with us ? It might be helpful to have a
> chat about these things.
> I have some ideas how to improve the run-time - binding process, but so far,
> it's just theory - might be very helpful to see your code...

I'd love to, but since it's for an unreleased work project I'm afraid
I can't share it.

Cheers,
- Tim.

Igor Minar

unread,
Aug 15, 2011, 10:29:51 AM8/15/11
to ang...@googlegroups.com
On Mon, Aug 15, 2011 at 2:44 AM, Tim Cuthbertson <gfx...@gmail.com> wrote:
Hi all,

I've used and greatly enjoyed angular on personal projects. Recently I
suggested using it for a work project. The prototype worked well but
suffered from some unfortunate performance issues, mostly related to
startup time on IE 7 (it locked up the browser on load for about 9
seconds, and this isn't even IE6 ;)).

Interesting.. I wonder what was going on there. Too bad that you can't share the code (or parts of it).
 
I'd have liked to delve into the performance issues at the time, but
didn't have the bandwidth and we went with the more lightweight manual
backbone.js instead. But I'm interested in thoughts on performance
now, even if it's sadly too late for this particular project.

It seemed a lot of the startup time was spent compiling templates and
initializing the system (callbacks, events, etc). I don't expect the
second part of that can be done ahead of time, but has there been any
thought given to precompiling templates? That could reduce the startup
time, but I'm not really sure how much time you would save given you
obviously still have to set up DOM events and other things on
initialization.

Another thought I had is more related to runtime performance than
initialization: is there any functionality in angular to cache
previously-computed values or parts-of-values? Say if I use object.foo.
$size() in ten different places in my template, will the size be
calculated ten times? How about if I use obj.foo.$size() as a
subexpression in other template values?

{{ object.foo.$size() }} is an expression that needs to be parsed before it can be evaluated.

We do have a cache that caches these result from the parser, but we currently don't cache results of the expression evaluations. It might be a good idea to add that in the future, but given that you rarely use the same binding over and over, I'm not sure how effective this would be.

/i
 

And when `obj` changes but `foo` remains the same, does anything get
re-calculated? It seems like it would be a lot of work an might not
work in an impure language like javascript, but there may be some
things that can be done.

Cheers,
 - Tim.

--
You received this message because you are subscribed to the Google Groups "angular" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.


Reply all
Reply to author
Forward
0 new messages