Skip to content

Performance: Object sleep API #191

@parasyte

Description

@parasyte

Following discussion on the forum, it sounds like a good idea to implement an object sleep mechanism to save CPU cycles for objects that have nothing to do.

The way I imagine it is having two pools for game objects; the gameObjects array in core.js, and a new array for sleepingObjects. Calling me.game.sleep(obj) will remove obj from gameObjects, and push it into sleepingObjects. And me.game.wakeup(obj) will do the opposite.

A sleeping object will never be iterated in the update or draw loops, saving precious CPU time.

Further, we can enable a flag like me.sys.enableAutoSleep to put objects to sleep when they leave the viewport. Deciding on a good method of waking up a sleeping object without polling will be crucial for this flag to be useful. I suppose worst-case, polling infrequently (once per second?) could work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions