Gamua / Starling-Framework

The Cross Platform Game Engine
http://www.starling-framework.org
Other
2.85k stars 819 forks source link

VertexData.setPoint() retrieves attribute offset from list every time when non-standard attribute is used? #890

Closed vroad closed 7 years ago

vroad commented 8 years ago

Doesn't this cause setPoint() to run slower? Or, is this not so slow on AS3?

I retrieve offset by myself before manipulating vertices, so I don't think it's inconvenient even if second parameter is an attribute offset, not a String.

https://github.com/Gamua/Starling-Framework/blob/870f0eade51a6a57df07302f27575edfb835cc8c/starling/src/starling/rendering/VertexData.as#L420

PrimaryFeather commented 8 years ago

Correct: it would be faster if developers would pass the offset directly.

What I tried to achieve with the new VertexData class is to create a compromise between extensibility, efficiency and usability. As a developer, you only need to remember the name of an attribute, and can use the class as easily as possible. Since "position" is the most often used attribute, I made a shortcut for that; all other attributes require an extra step of one method call.

According to my tests, though, this was not as expensive as one could expect. Furthermore, what's much more important for performance is the cost of copyTo, because that accesses every vertex and every attribute, every frame. (For batching.) Changing specific attributes is typically not done as much, by far.

PrimaryFeather commented 8 years ago

Furthermore, if you run into a situation where this does turn into a bottleneck, you can always access the ByteArray directly. Then you'll even spare one more method call.