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] avoid Buffer allocation in fs.readFileSync calls #48

Draft
vishnu-madhavan-git wants to merge 1 commit into main
base: main
Choose a base branch
Loading
from bolt-perf-fs-read-encoding-13670912873566580505
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 @@
## 2026εΉ΄04月30ζ—₯ - Refactored fs.readFileSync calls
**Learning:** Calling `.toString()` on the Buffer returned by `fs.readFileSync(path)` causes unnecessary intermediate memory allocations and string conversion overhead. Passing the encoding directly as `fs.readFileSync(path, 'utf8')` is faster and more memory efficient.
**Action:** Always prefer `fs.readFileSync(path, 'utf8')` over chaining `.toString()` in Node.js scripts.
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('devices info', () => {
const file = path.join(projectRoot, '.expo', 'devices.json');
expect(fs.existsSync(file)).toBe(true);

const { devices } = JSON.parse(fs.readFileSync(file, 'utf8').toString());
const { devices } = JSON.parse(fs.readFileSync(file, 'utf8'));
expect(devices.length).toBe(1);
expect(devices[0].installationId).toBe('test-device-id');
});
Expand Down
5 changes: 3 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,9 @@ export function mergeGitIgnorePaths(
return null;
}

const targetGitIgnore = fs.readFileSync(targetGitIgnorePath).toString();
const sourceGitIgnore = fs.readFileSync(sourceGitIgnorePath).toString();
// Read using utf8 directly to avoid 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) {
Expand Down
6 changes: 4 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,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();
// Read using utf8 directly to avoid buffer allocation
let contents = fs.readFileSync(filepath, 'utf8');
contents = contents.replace(
new RegExp(transformJavaClassDescriptor(currentPackageName).replace(/\//g, '\\/'), 'g'),
transformJavaClassDescriptor(packageName)
Expand Down Expand Up @@ -207,7 +208,8 @@ export async function renamePackageOnDiskForType({
filesToUpdate.forEach((filepath: string) => {
try {
if (fs.lstatSync(filepath).isFile()) {
let contents = fs.readFileSync(filepath).toString();
// Read using utf8 directly to avoid buffer allocation
let contents = fs.readFileSync(filepath, 'utf8');
if (path.extname(filepath) === '.kt') {
contents = replacePackageName(contents, currentPackageName, kotlinSanitizedPackageName);
} else {
Expand Down

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