Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on May 4, 2026. It is now read-only.

⚑ Bolt: [performance improvement] Optimize readFileSync encoding #49

Draft
vishnu-madhavan-git wants to merge 1 commit into main
base: main
Choose a base branch
Loading
from bolt/optimize-read-file-sync-13634680265143971799
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2024εΉ΄05月24ζ—₯ - readFileSync toString buffer allocation bypass
**Learning:** In standard Node.js applications, omitting the encoding parameter on `readFileSync` reads the file as a raw `Buffer`. If the immediate next operation is `.toString()`, this incurs an extra, temporary memory allocation for the intermediate buffer object that is then garbage collected. This is a common but subtle memory overhead pattern.
**Action:** Always prefer `readFileSync(path, 'utf8')` over `readFileSync(path).toString()` to directly create the string from the C++ layer and skip intermediate buffer allocations.
4 changes: 2 additions & 2 deletions packages/@expo/cli/src/utils/mergeGitIgnorePaths.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export function mergeGitIgnorePaths(
return null;
}

const targetGitIgnore = fs.readFileSync(targetGitIgnorePath).toString();
const sourceGitIgnore = fs.readFileSync(sourceGitIgnorePath).toString();
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) {
Expand Down
4 changes: 2 additions & 2 deletions packages/@expo/config-plugins/src/android/Package.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ 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();
let contents = fs.readFileSync(filepath, 'utf8');
contents = contents.replace(
new RegExp(transformJavaClassDescriptor(currentPackageName).replace(/\//g, '\\/'), 'g'),
transformJavaClassDescriptor(packageName)
Expand Down Expand Up @@ -207,7 +207,7 @@ export async function renamePackageOnDiskForType({
filesToUpdate.forEach((filepath: string) => {
try {
if (fs.lstatSync(filepath).isFile()) {
let contents = fs.readFileSync(filepath).toString();
let contents = fs.readFileSync(filepath, 'utf8');
if (path.extname(filepath) === '.kt') {
contents = replacePackageName(contents, currentPackageName, kotlinSanitizedPackageName);
} else {
Expand Down
9 changes: 5 additions & 4 deletions packages/expo-brownfield/plugin/src/common/filesystem.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ const maybeReadOverwrittenTemplate = (template: string, platform?: PlatformStrin
try {
accessSync(path.join(process.cwd(), '.brownfield-templates'));
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 {}
Expand All @@ -55,7 +56,7 @@ const readTemplate = (template: string, platform?: PlatformString): string => {
throw new Error(`Template ${template} doesn't exist at ${templatePath}`);
}

return readFileSync(templatePath).toString();
return readFileSync(templatePath, 'utf8');
};

const createFileFromTemplateInternal = (
Expand Down
2 changes: 1 addition & 1 deletion packages/pod-install/src/index.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async function runAsync(maybeProjectDirectory?: string): Promise<void> {
process.exit(1);
}

const jsonData = JSON.parse(readFileSync(packageJsonPath).toString());
const jsonData = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
const hasExpoPackage = jsonData.dependencies?.hasOwnProperty('expo');

if (hasExpoPackage) {
Expand Down

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /