[OpenLayers-Dev] Re: [OpenLayers 3] type instantiation performance

Eric Lemoine eric.lemoine at camptocamp.com
Sun Oct 17 07:24:31 EDT 2010


On Sunday, October 17, 2010, Peter Robins <openlayers at peterrobins.co.uk> wrote:
> On 16 October 2010 13:37, Eric Lemoine <eric.lemoine at camptocamp.com> wrote:
>> So should we consider changing the way we create types in OpenLayers?
>
> could you clarify what you mean by 'types' here? When I first read
> your post, I was thinking you were thinking only of changing this in
> drag/pan actions, but reading it again it looks like you're proposing
> getting rid of OpenLayers.Class completely. (I'm not saying that's a
> bad idea, but it would be a major change!)

Hi Peter

Yes, my email was questioning OpenLayers.Class. I tend to think
OpenLayers.Class represents an unnecessary level of abstraction for
OpenLayers, causing significant overhead when lots of objects need to
be created (which is currently the case when panning the map). This
overhead comes from calling "apply" (initialize.apply in the "Class"
function) for every object creation.

To illustrate again how things would look like with what I'm
proposing, here's an example involving OL.Layer and OL.Layer.Vector,
assuming the latter inherits from the former:

OL.Layer = function(options) {
    // constructor
    ...
};
OL.Layer.prototype = {
    // prototype
    ...
}
OL.Layer.Vector = function(options) {
     OL.Layer.call(this, options);
     ...
};
OL.inherit(OL.Layer.Vector, OL.Vector, {
     // prototype
     ...
});

With this we directly call the constructor when creating simple
objects. (For objects whose types are inherited types we still use
"call" (or "apply") to call to parent constructor, but this is
inevitable.)

I don't think this is such a major change. It would basically just
involve changing a few lines in all the files including class
definitions. But maybe you see this as a major change for other
aspects?

As Andreas said, we could also address the overhead issue by using
object litterals. Yet, I'm still not sure we'd be able to use object
litterals for every type that's causing us problem today. For example,
we create lots of Bounds when panning the map, and we apply methods to
these methods, like containsBounds, so replacing them with object
litterals might not be straightforward. But if only Bounds is causing
us trouble we could decide to modify the way the OpenLayers.Bounds
type is defined (using plain JavaScript as for OL.Layer above), and
still use OpenLayers.Class for defining the other types in the lib.

Anyway, I just meant to have people's opinion about this.

Thanks,


More information about the Dev mailing list