Gamecore.js: increase javascript game performance by 1200%

At a talk I gave at the recent HTML5 Developers Conference in San Francisco, I covered some of the performance issues we had whilst building the Playcraft Engine. Notably, trying to get a working class framework with static inheritance, as well as memory issues associated with excessive object garbage collection in Javascript virtual machines (JVM’s).

I think we solved those problems in a pretty cool way, and decided to open-source the code (check it out on https://github.com/playcraft/gamecore.js) as gamecore.js.

Using gamecore.js for object pooling, we’ve seen massive reductions in garbage collection, and a reduction in memory footprint. In one of our demo games, a high-speed space shooter, garbage collection was reduced 95% — resulting in around a 1200% jump in performance — simply by subclassing from gamecore.Pooled.

Here’s a quick overview.

gamecore.js is made up of 5 components:

  • gamecore.Base – an implementation of class.js (static inheritance, super methods and introspection) with some added bug fixes as well as per class (simple) logging, and unique object ids.
  • gamecore.Pooled – garbage collection bad, automatic super-fast object pooling good!
  • gamecore.LinkedList – a high-performance double linked list
  • gamecore.Device – a device independent map (well, a start at one anyway)
  • gamecore.PerformanceMeasure – a first stab at a simple performance collector with shimming.
  • gamecore.Hashtable – Tim Down’s awesome hashtable.

gamecore.js isn’t a game engine; it’s just a set of foundation classes you can use to build cool game code, and not have to worry about things like the garbage collector. We’re also hoping that others building libraries intended for gaming take advantage of the object pooling to save us all time in the future.

Some quick examples:

Create a class

 

Inherit through subclassing

 

Super easy object pooling
gamecore.Pooled will handle the construction and assignment

 

Doubly Linked Lists
Super fast for adding, removing, looping with low memory overhead

There’s more to explore in gamecore.js, including a device map (for quick shimming of device details) and a cool hashmap. Feel free to play around and give us feedback.

You can access gamecore.js on github.

If you’re looking for a complete HTML5/Javascript game engine then join the Playcraft Engine beta.

Bookmark the permalink.

8 Comments

Leave a comment