Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Perf improvements #7759

Closed
wants to merge 15 commits into from
Closed

Perf improvements #7759

wants to merge 15 commits into from

Conversation

IgorMinar
Copy link
Contributor

No description provided.

IgorMinar added 15 commits June 4, 2014 07:08
In apps that create lots of scopes (apps with large tables) the uid generation
shows up in the profiler and adds a few milliseconds. Using simple counter
doesn't have this overhead.

I think the initial fear of overflowing and thus using string alphanum sequence
is unjustified because even if an app was to create lots of scopes non-stop,
you could create about 28.6 million scopes per seconds for 10 years before
you would reach a number that can't be accurately represented in JS

BREAKING CHANGE: Scope#$id is now of time number rather than string. Since the
id is primarily being used for debugging purposes this change should not affect
anyone.
Micro-optimization :-)

BREAKING CHANGE: forEach will iterate only over the initial number of items in
the array. So if items are added to the array during the iteration, these won't
be iterated over during the initial forEach call.

This change also makes our forEach behave more like Array#forEach.
Since we allow only one copy of Angular to be loaded at a time it doesn't
make much sense randomly generate the expando property name and then be
forced to use slow reflective calles to retrieve the IDs.
This is what jQuery does by default: https://github.com/jquery/jquery/blob/c18c6229c84cd2f0c9fe9f6fc3749e2c93608cc7/src/data/accepts.js#L16

We don't need to set data on text/comment nodes internally and if we don't
allow setting data on these nodes, we don't need to worry about cleaning
it up.

BREAKING CHANGE: previously it was possible to set jqLite data on Text/Comment
nodes, but now that is allowed only on Element and Document nodes just like in
jQuery. We don't expect that app code actually depends on this accidental feature.
Iterate only over elements and not nodes since we don't attach data or handlers
to text/comment nodes.
All elements/browsers that don't have classList will still use the old setTimeout method.
This code is very hot and in most cases we are wrapping just a single Node so
we should optimize for that scenario.
Each window has a reference to itself, which is pretty unique so we can use
that to simplify our isWindow check
This maskes looking at stack traces easier.

Since we generate the callbacks for each event type at runtime and we can't
set function's name because it's read-only, we have to use a generic name.
This change is not compatible with IE8.
…single element

This affects jqLite#html, #text, #attr, #prop, #css and others.
@mary-poppins
Copy link

Thanks for the PR! Please check the items below to help us merge this faster. See the contributing docs for more information.

  • Uses the issue template (#7759)

If you need to make changes to your pull request, you can update the commit with git commit --amend.
Then, update the pull request with git push -f.

Thanks again for your help!

@IgorMinar IgorMinar added cla: yes and removed cla: no labels Jun 9, 2014
@lgalfaso
Copy link
Contributor

lgalfaso commented Jun 9, 2014

Overall, looks good

@rodyhaddad
Copy link
Contributor

Landed as 9971fbb...65a44dd in master

And 8661a9e...81b7e5a in v1.2.x

The things in master that currently aren't in v1.2.x, but should be considered for the next stable release are:

  • using classList in add/remove class (using classList.add.apply caused issues on IE 10/11)
  • isWindow optimization (I saw IE 8 failing for this, might want to investigate more)
  • Changing the expando property to .ng to avoid reflection (IE8 puts ng as an attribute, and our 1.2.x test currently filter out ng-\d+)

I'll leave this issue open until we settle the 3 points above for 1.2.x.
Moving this to the next milestone.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants