onnxruntime
a5dc0f95 - [web] use shorter memory info name for WebGPU buffer and WebNN tensor (#27207)

Commit
5 days ago
[web] use shorter memory info name for WebGPU buffer and WebNN tensor (#27207) ### Description This PR renames the following existing names for MemoryInfo: - `WebGPU_Buffer` -> `WebGPU_Buf` - `WebNN_Tensor` -> `WebNN_Ten` ### Motivation and Context the `OrtMemoryInfo` uses a `std::string` to store the name. modern C++ compilers uses "small string optimization" (SSO) to avoid an extra memory allocation if the string is small enough. While different compiler may have different implementation, the following test program is used to test what exact limit is for a certain compiler: ```c++ #include <string> #include <cstdio> int main() { std::string webgpu0 = "WebGPU_Buf"; std::string webgpu1 = "WebGPU_Buff"; std::string webgpu2 = "WebGPU_Buffe"; std::string webgpu3 = "WebGPU_Buffer"; printf("=========== %s\n string address: %p\n data address : %p\n\n", webgpu0.c_str(), (void*)&webgpu0, (void*)webgpu0.data()); printf("=========== %s\n string address: %p\n data address : %p\n\n", webgpu1.c_str(), (void*)&webgpu1, (void*)webgpu1.data()); printf("=========== %s\n string address: %p\n data address : %p\n\n", webgpu2.c_str(), (void*)&webgpu2, (void*)webgpu2.data()); printf("=========== %s\n string address: %p\n data address : %p\n\n", webgpu3.c_str(), (void*)&webgpu3, (void*)webgpu3.data()); return 0; } ``` While using emscripten (targetting wasm32), the runtime result is like this: ``` =========== WebGPU_Buf string address: 0x10db0 data address : 0x10db0 =========== WebGPU_Buff string address: 0x10da4 data address : 0x10dc8 =========== WebGPU_Buffe string address: 0x10d98 data address : 0x10de0 =========== WebGPU_Buffer string address: 0x10d8c data address : 0x10df8 ``` Which shows that the string need to be no more than 10 bytes (exclude the '\0' at end) to enable SSO.
Author
Parents
Loading