Файли
openidea/src/platform/base64.ts
T
Mr0Bread 23f591289c perf(ipc): send binary command arguments as base64 instead of number arrays (#5436)
Pasting an image into a terminal or a Markdown file, or saving bytes from the UI, sent the data as a JSON array of numbers (3.6x the size), which Tauri and the remote server parse into a serde_json::Value first (~50x the bytes in memory: a 20 MB image took ~2.2 GB peak heap and 640 ms). Binary command arguments (fs_create_file_bytes, term_store_image) now travel as base64 text (IpcBytes): the same 20 MB takes ~112 MB and 32 ms. Native image drops reuse the base64 they already have.

Co-authored-by: Mr0Bread <[email protected]>
2026-11-23 22:32:58 +08:00

12 рядки
539 B
TypeScript

/**
* Binary command arguments (`IpcBytes` in Rust) cross IPC as base64 text: as a JSON number array
* they take 3.6x the size and a parsed `Value` tree of roughly 50x.
*/
export function toBase64(bytes: Uint8Array): string {
const parts: string[] = [];
// `apply` with a typed array is about 5x faster than spreading it (20 MB: 70 ms vs 380 ms).
for (let i = 0; i < bytes.length; i += 0x8000)
parts.push(String.fromCharCode.apply(null, bytes.subarray(i, i + 0x8000) as unknown as number[]));
return btoa(parts.join(""));
}