Skip to content

Commit 4e4e204

Browse files
author
Ben Newman
committed
Write .meteor-portable-2.json files synchronously.
Previously these files were written asynchronously in an attempt to improve performance, since the success of the write is not critical. While I stand by my claim that it's acceptable for these writes to fail, I noticed recently that the async write was failing very often (resulting in an empty .meteor-portable-2.json file). Switching to sync semantics eliminated that problem with no noticeable loss of performance. In fact, overall performance is likely better because of the future work saved by a successful write.
1 parent bcd0ac0 commit 4e4e204

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

tools/isobuild/meteor-npm.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -528,21 +528,20 @@ const isPortable = Profile("meteorNpm.isPortable", dir => {
528528
isPortable(files.pathJoin(dir, itemName)));
529529

530530
if (canCache) {
531-
// Write the .meteor-portable file asynchronously, and don't worry
532-
// if it fails, e.g. because the file system is read-only (#6591).
533-
// Failing to write the file only means more work next time.
534-
fs.writeFile(
535-
portableFile,
536-
JSON.stringify(result) + "\n",
537-
error => {
538-
// Once the asynchronous write finishes (successful or not), we no
539-
// longer need to cache the written value in memory.
540-
delete portableCache[portableFile];
541-
},
542-
);
531+
try {
532+
files.writeFile(
533+
portableFile,
534+
JSON.stringify(result) + "\n",
535+
"utf8"
536+
);
537+
} catch (ignored) {
538+
// Don't worry if the write fails, e.g. because the file system is
539+
// read-only (#6591). Failing to write the file only means more work
540+
// next time.
541+
}
543542

544-
// Cache the result immediately in memory so that the asynchronous
545-
// write won't confuse synchronous optimisticReadJsonOrNull calls.
543+
// Cache the result immediately in memory so we don't have to wait for
544+
// file change notifications to invalidate optimisticReadJsonOrNull.
546545
portableCache[portableFile] = result;
547546
}
548547

0 commit comments

Comments
 (0)