From 3f4fbca7213fbfad92758bdf7a135344f9c51452 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 15 Apr 2026 08:14:06 +0000 Subject: [PATCH] perf: optimize `fs.readFileSync` calls by passing encoding directly Replaced `fs.readFileSync(path).toString()` with `fs.readFileSync(path, 'utf8')` in `@expo/cli` and `@expo/config-plugins`. This micro-optimization directly passes the encoding to the filesystem API, which avoids an intermediate `Buffer` allocation and subsequent garbage collection overhead. Added inline comments to document the performance benefit. Co-authored-by: vishnu-madhavan-git <237662584+vishnu-madhavan-git@users.noreply.github.com> --- .jules/bolt.md | 0 packages/@expo/cli/src/utils/mergeGitIgnorePaths.ts | 5 +++-- packages/@expo/config-plugins/src/android/Package.ts | 6 ++++-- 3 files changed, 7 insertions(+), 4 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/cli/src/utils/mergeGitIgnorePaths.ts b/packages/@expo/cli/src/utils/mergeGitIgnorePaths.ts index dab487df678413..63522ff8aaeb0f 100644 --- a/packages/@expo/cli/src/utils/mergeGitIgnorePaths.ts +++ b/packages/@expo/cli/src/utils/mergeGitIgnorePaths.ts @@ -35,8 +35,9 @@ export function mergeGitIgnorePaths( return null; } - const targetGitIgnore = fs.readFileSync(targetGitIgnorePath).toString(); - const sourceGitIgnore = fs.readFileSync(sourceGitIgnorePath).toString(); + // Performance: Pass 'utf8' encoding directly to avoid intermediate Buffer allocation + const targetGitIgnore = fs.readFileSync(targetGitIgnorePath, 'utf8'); + const sourceGitIgnore = fs.readFileSync(sourceGitIgnorePath, 'utf8'); const merged = mergeGitIgnoreContents(targetGitIgnore, sourceGitIgnore); // Only rewrite the file if it was modified. if (merged.contents) { diff --git a/packages/@expo/config-plugins/src/android/Package.ts b/packages/@expo/config-plugins/src/android/Package.ts index 96222ebf4ba553..8f360326f69252 100644 --- a/packages/@expo/config-plugins/src/android/Package.ts +++ b/packages/@expo/config-plugins/src/android/Package.ts @@ -125,7 +125,8 @@ export async function renameJniOnDiskForType({ filesToUpdate.forEach((filepath: string) => { try { if (fs.lstatSync(filepath).isFile() && ['.h', '.cpp'].includes(path.extname(filepath))) { - let contents = fs.readFileSync(filepath).toString(); + // Performance: Pass 'utf8' encoding directly to avoid intermediate Buffer allocation + let contents = fs.readFileSync(filepath, 'utf8'); contents = contents.replace( new RegExp(transformJavaClassDescriptor(currentPackageName).replace(/\//g, '\\/'), 'g'), transformJavaClassDescriptor(packageName) @@ -207,7 +208,8 @@ export async function renamePackageOnDiskForType({ filesToUpdate.forEach((filepath: string) => { try { if (fs.lstatSync(filepath).isFile()) { - let contents = fs.readFileSync(filepath).toString(); + // Performance: Pass 'utf8' encoding directly to avoid intermediate Buffer allocation + let contents = fs.readFileSync(filepath, 'utf8'); if (path.extname(filepath) === '.kt') { contents = replacePackageName(contents, currentPackageName, kotlinSanitizedPackageName); } else {