Skip to content

⚡️ Performance: Investigate using a Set to store actors, not an array #135

@JoshuaKGoldberg

Description

@JoshuaKGoldberg

Bug Report Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have pulled the latest main branch of the repository.
  • I have searched for related issues and found none that matched my issue.

Overview

Right now, emojisplosion internally uses an the Animator class to run the regular gameplay loop of telling EmojiActors ("actors") to animate. It stores actors in an array internally:

https://github.com/JoshuaKGoldberg/emojisplosion/blob/fe1ef216a89d6dd32bc5e752e203ceb66206c6d7/src/animator.ts#L11-L14

Whenever an actor "dies" (leaves the screen area), it's removed from that array with a .splice:

https://github.com/JoshuaKGoldberg/emojisplosion/blob/fe1ef216a89d6dd32bc5e752e203ceb66206c6d7/src/animator.ts#L52-L57

I wonder if that's actually inefficient? Now that all browsers have Sets, should we look into going with a Set for storage, so that it has O(1) removals?

Additional Info

...alternately, should we loop from the end of the actors array to the beginning (let i = actors.length - 1; i >= 0; i -= 1)?

Investigation needed!

Since this is a performance investigation, we'd need real data in multiple popular browsers (Chrome, Firefox, Safari) to indicate whether any approach is noticeably better or worse than others.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions