oakes / play-clj

A Clojure game library
The Unlicense
939 stars 73 forks source link

avoid reflection for performance #77

Closed floybix closed 9 years ago

floybix commented 9 years ago

Hi, these showed up in some profiling i did: isa? (and its underlying Class.getInterfaces) and reflection on .get in tiled-map-renderer*.

oakes commented 9 years ago

Thanks! I don't think we can assume that tiled-map-layer accepts a string, because people may be passing an index to it. Other than that it looks great.

floybix commented 9 years ago

That reflection on .get is a major hit to performance because it is called so often - on every render cycle many times to check valid movement of entities.

The following could avoid the reflection:

        (let [layers (-> ^BatchTiledMapRenderer (u/get-obj screen :renderer)
                         .getMap
                         .getLayers)]
          (if (number? layer)
            (.get layers (int layer))
            (.get layers (str layer)))))))
oakes commented 9 years ago

OK that sounds good, can you send a PR? On Mar 16, 2015 9:41 AM, "Felix Andrews" notifications@github.com wrote:

That reflection on .get is a major hit to performance because it is called so often - on every render cycle many times to check valid movement of entities.

The following could avoid the reflection:

    (let [layers (-> ^BatchTiledMapRenderer (u/get-obj screen :renderer)
                     .getMap
                     .getLayers)]
      (if (number? layer)
        (.get layers (int layer))
        (.get layers (str layer)))))))

Reply to this email directly or view it on GitHub https://github.com/oakes/play-clj/pull/77#issuecomment-81669388.