The Wikipedia articles on them have pseudo code on how they are done. In construct I’d say utilize the json plugin to manage the data structures needed, although they probably could be done with arrays albeit with some tedium.
There are simpler structures like a uniform grid with a list of the objects in them, as well as binary space partitions that may work well too.
If your levels has stuff mostly on a grid I’ve had great speed boosts from using and array to store if a grid location has an object or not.
Guess the gist of all of them is adding/removing objects from the structure, and getting a list of objects overlapping an aabb.
Event loops and picking kind of slow things down so for the greatest benefit I’d recommend utilizing JavaScript to do it if you can.
So I’d say best, as in fastest, would be going with JavaScript.
If utilizing just events, use json.
But those are just general ideas.