Skip to content

Conversation

@fs-eire
Copy link
Contributor

@fs-eire fs-eire commented Oct 28, 2025

Description

optimize emscripten inter-op for buffer.

There are huge amount of calls to WebGPU API wgpuBufferGetSize and wgpuBufferGetUsage. The original implementation was using inter-op (JavaScript implementation). This change modifies the implementation to use C++ code so that inter-op is avoid.

In order to achieve this, I need to add 2 fields mSize and mUsage into WGPUBufferImpl class and value of those fields are set in constructor. This should be safe considering those 2 properties of a buffer is immutable.

Motivation and Context

Improve E2E perf

@fs-eire fs-eire requested a review from Copilot October 29, 2025 00:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a performance optimization patch for Emscripten-based WebGPU interop by caching buffer size and usage fields in the C++ WGPUBufferImpl class to avoid frequent JavaScript-to-C++ boundary crossings.

Key Changes:

  • Adds new patch file emscripten_interop_opt.patch that caches buffer size and usage as fields in WGPUBufferImpl
  • Removes JavaScript functions wgpuBufferGetSize and wgpuBufferGetUsage that previously crossed the JS/C++ boundary
  • Updates the Dawn patch command in CMake to apply the new optimization patch

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
cmake/patches/dawn/emscripten_interop_opt.patch New patch file that modifies Dawn's Emscripten WebGPU implementation to cache buffer metadata in C++
cmake/external/onnxruntime_external_deps.cmake Adds application of the new optimization patch to the Dawn build process

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@fs-eire fs-eire changed the title [WIP][webgpu] optimize emscripten inter-op for buffer [webgpu] optimize emscripten inter-op for buffer Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants