From 0aeb9cacc6f6662ee23f681ed026769391b24c6f Mon Sep 17 00:00:00 2001 From: Roni Gordon Date: Fri, 12 Jun 2026 10:33:07 -0400 Subject: [PATCH] perf: use String.fromCharCode.apply in floats32ToBase64 example --- extensions/community_extensions/agentic-audiences.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/extensions/community_extensions/agentic-audiences.md b/extensions/community_extensions/agentic-audiences.md index 3c72dc9..d28f161 100644 --- a/extensions/community_extensions/agentic-audiences.md +++ b/extensions/community_extensions/agentic-audiences.md @@ -70,8 +70,9 @@ function floats32ToBase64(arr) { const view = new DataView(buffer); arr.forEach((x, i) => view.setFloat32(i * 4, x, true)); // little-endian const bytes = new Uint8Array(buffer); - let binary = ""; - for (const b of bytes) binary += String.fromCharCode(b); + // apply() converts all bytes in one call, avoiding per-byte string re-allocations. + // For very large inputs, chunk into ~8192-byte blocks to stay within engine argument limits. + const binary = String.fromCharCode.apply(null, bytes); return btoa(binary); }