I’ll probably end up implementing a quadtree, or a grid-based acceleration structure, since currently the complexity is currently n squared in a worst case. I’ll let you know how I get on with this.
Break something expensive
inputs = [.., .., .., ..] outputs =  interval = null interval = setInterval( => tzero = (new Date).getTime() while ((new Date).getTime() - tzero < 50) and (inputs.length > 0) input = inputs.pop() outputs.push( doSomethingExpensiveWith(input) ) if inputs.length == 0 clearInterval(interval) console.log(outputs) , 100)
I might pull that code out into a generalised form (since I could use it throughout the app) and also add support for chaining inputs and outputs:
Something like that would be pretty cool, but the above code is the simplified version that works for me.