molstar icon indicating copy to clipboard operation
molstar copied to clipboard

improve bond iterator allocations by using a state/context object

Open arose opened this issue 2 years ago • 0 comments

          Creating two closures inside a loop isn't exactly cheap. Tho I guess it shouldn't be a problem in this particular case.

If you feel like it in the future, there is a way to avoid creating the closure with something like this:

function eachIntraBondedAtom(unit, idx, cb, thisArg?: State) {
   for (const b of ...) {
     cb.call(thisArg, x, y);
   }
}

and then the callback can be a top-level function like this:

function eachBond(this: State, x, y) {
  this.whatever = x;
}

Originally posted by @dsehnal in https://github.com/molstar/molstar/pull/797#discussion_r1186795226

arose avatar May 08 '23 02:05 arose