From 84ad73cad84db9b339ac70e6b248fe2bbdb2f16e Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 9 Apr 2026 08:09:11 +0000 Subject: [PATCH] perf: optimize readFileSync calls by passing utf8 encoding directly - Replaced `readFileSync(...).toString()` with `readFileSync(..., 'utf8')` in `packages/pod-install/src/index.ts` and `packages/expo-brownfield/plugin/src/common/filesystem.ts`. - This avoids unnecessary intermediate memory allocations for buffers before converting to strings. Co-authored-by: vishnu-madhavan-git <237662584+vishnu-madhavan-git@users.noreply.github.com> --- .jules/bolt.md | 0 .../expo-brownfield/plugin/src/common/filesystem.ts | 11 +++++++---- packages/pod-install/src/index.ts | 3 ++- 3 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 .jules/bolt.md diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/packages/expo-brownfield/plugin/src/common/filesystem.ts b/packages/expo-brownfield/plugin/src/common/filesystem.ts index dfbcceaeb05b2d..ef944baad6a851 100644 --- a/packages/expo-brownfield/plugin/src/common/filesystem.ts +++ b/packages/expo-brownfield/plugin/src/common/filesystem.ts @@ -25,14 +25,16 @@ const interpolateVariables = (str: string, variables: Record): const maybeReadOverwrittenTemplate = (template: string, platform?: PlatformString): string => { try { accessSync(path.join(process.cwd(), '.brownfield-templates')); + // ⚡ Bolt Optimization: Pass 'utf8' encoding directly to avoid unnecessary intermediate buffer allocation if (existsSync(path.join(process.cwd(), '.brownfield-templates', template))) { - return readFileSync(path.join(process.cwd(), '.brownfield-templates', template)).toString(); + return readFileSync(path.join(process.cwd(), '.brownfield-templates', template), 'utf8'); } if (existsSync(path.join(process.cwd(), '.brownfield-templates', platform ?? '.', template))) { return readFileSync( - path.join(process.cwd(), '.brownfield-templates', platform ?? '.', template) - ).toString(); + path.join(process.cwd(), '.brownfield-templates', platform ?? '.', template), + 'utf8' + ); } // eslint-disable-next-line no-empty } catch {} @@ -55,7 +57,8 @@ const readTemplate = (template: string, platform?: PlatformString): string => { throw new Error(`Template ${template} doesn't exist at ${templatePath}`); } - return readFileSync(templatePath).toString(); + // ⚡ Bolt Optimization: Pass 'utf8' encoding directly to avoid unnecessary intermediate buffer allocation + return readFileSync(templatePath, 'utf8'); }; const createFileFromTemplateInternal = ( diff --git a/packages/pod-install/src/index.ts b/packages/pod-install/src/index.ts index 15184c3f113372..80a7aa50efdec5 100644 --- a/packages/pod-install/src/index.ts +++ b/packages/pod-install/src/index.ts @@ -41,7 +41,8 @@ async function runAsync(maybeProjectDirectory?: string): Promise { process.exit(1); } - const jsonData = JSON.parse(readFileSync(packageJsonPath).toString()); + // ⚡ Bolt Optimization: Use 'utf8' encoding directly in readFileSync to avoid unnecessary memory allocation for the intermediate buffer + const jsonData = JSON.parse(readFileSync(packageJsonPath, 'utf8')); const hasExpoPackage = jsonData.dependencies?.hasOwnProperty('expo'); if (hasExpoPackage) {