#15482·bokeh

Avoid unnecessary allocations when applying selection from Bitset

Author: muendleinCreated Oct 1, 2026Updated Oct 1, 2026
Labelstag: component: bokehjstag: performance

Currently an intermediate indices array is created when using Bitset to select a subset of an array. This can be avoided yielding a small performance boost.

  select<T>(array: Arrayable<T>): Arrayable<T> {
    assert(this.size <= array.length, "Size mismatch")
    const n = this.count
    const result = new (array.constructor as ArrayableNew)<T>(n)
    const indices = this.ones() // this is not necessary
    let i = 0
    for (let j = 0; j < indices.length; j++) {
      result[i++] = array[indices[j]]
    }
    return result
  }