Skip to content

The cost of ArrayBuffer creation #501

@kvark

Description

@kvark

In the discussions around data transfers (e.g. #491), vertex buffers, and other parts, we repeatedly hit a case where the cost of creating many ArrayBuffer objects should be considered. I wanted to see if we have concrete evidence to inform the costs here, so I made a small benchmark - https://jsperf.com/mass-arraybuffer-creation/1

Basically, all the browsers can comfortably create more than a million ArrayBuffer objects per second, even when:

  1. they are wrapped into new Int32View wrappers, which isn't necessarily the case for WebGPU usage.
  2. no explicit detaching is invoked, while WebGPU would know at concrete time when to unlink the storage (e.g. GPUUploadPass.finish()).
  3. data is allocated on the heap, while WebGPU will in most cases provide access to external data that already exists (and if not, the costs of managing this data are not something we are trying to save here, we are only talking about ArrayBuffer objects themselves).
  4. Gecko JS engine isn't doing the best job at GC-managing ArrayBuffer objects specifically (can't tell about others), we have a room for optimization here.
  5. benchmarking overhead is not considered, which could take place since our iteration is so small

That gives more than 10K objects per frame, and possibly higher. In different words, if 100 ArrayBuffer objects are constructed per frame, when running at 100+ fps, we'd be losing less than 1% of the content process CPU time.

I'm not trying to drive any conclusions from this, just attempting to align our expectations in the context of the future discussions. If you think the benchmark is bad (and I feel bad), please help making it better :)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions