OpenLayers OpenLayers

Ticket #1106 (closed bug: fixed)

Opened 1 year ago

Last modified 1 year ago

minor performance optimization in Grid.js loops

Reported by: pspencer Assigned to: euzuro
Priority: minor Milestone: 2.6 Release
Component: Layer.Grid Version: 2.5
Keywords: Cc:
State:

Description

One known performance penalty in javascript is accessing properties of objects using the dot operator. It is generally considered to be more performant if properties are deferenced to a scope variable, especially when the property is accessed several times in one scope. This is especially important in loops that are run often or are large.

Grid.js contains a number of loops that operate on the entire set of tiles. Most of these loops use the above technique of dereferencing properties for scope access in the inner loops. There are a couple of notable exceptions, including one case where a row is dereference but the dereferenced var is not actually used for access.

Also, there is one case where parseInt(this.map.layerContainerDiv.style.top) (and left) is called repeated in an inner loop to calculate exactly the same value - the value of top and left are not changed in the loop as far as I can tell - so I propose to move the calculation to happen once outside the loop.

The attached diff contains the appropriate patches against r5050 (head at the time I filed this).

Attachments

patch.diff (2.2 kB) - added by pspencer on 10/23/07 22:41:50.
patch for Grid.js enhancements

Change History

10/23/07 22:41:50 changed by pspencer

  • attachment patch.diff added.

patch for Grid.js enhancements

10/24/07 08:14:24 changed by crschmidt

Have you profiled this? Does it increase speed?

The Firebug profiler is pretty good -- a 'before' and 'after' report would make me feel better about putting this in.

10/29/07 17:15:48 changed by tschaub

I know there is good reason not to spend time on premature optimization. However, I think this all fits in to good programming style. It should be well known that you pull repeated operations out of loops - and we should not have to generate performance stats to make this sort of change.

So, the parseInt stuff is clearly better written in the patch.

I know that lookups in the window namespace are expensive - but have no idea if the savings on that grid lookup is noticible (would be interesting to see).

In general, I'm in favor of looking for opportunities to increase performance in OL.

11/21/07 10:21:35 changed by crschmidt

  • keywords changed from review to commit.

Yeah, I was just curious. I didn't want to review at the time, and wanted some motivation :)

Paul: This looks fine, please go ahead and commit.

11/21/07 15:14:53 changed by pagameba

  • keywords deleted.
  • status changed from new to closed.
  • resolution set to fixed.

(In [5243]) apply patch from #1106, minor tweaks for performance. (Closes #1106)