Express: Express is using sync APIs, node --trace-sync-io complains

Created on 29 Mar 2016  路  3Comments  路  Source: expressjs/express

... when rendering views, in this func in lib/view.js

function tryStat(path) {
  debug('stat "%s"', path);

  try {
    return fs.statSync(path);
  } catch (e) {
    return undefined;
  }
}
question

Most helpful comment

Correct, rendering the view will perform a sync operation. You should have caching of views turned on and then only the first hit is sync, and further hits to that view are no file system operations at all.

Unfortunately the views system was written in a way that cannot be converted to async without breaking everything, so it won't be completely async until Express 5.0. Using view caching in your production code will avoid this issue once each of your views have been hit once.

All 3 comments

Correct, rendering the view will perform a sync operation. You should have caching of views turned on and then only the first hit is sync, and further hits to that view are no file system operations at all.

Unfortunately the views system was written in a way that cannot be converted to async without breaking everything, so it won't be completely async until Express 5.0. Using view caching in your production code will avoid this issue once each of your views have been hit once.

You can also find all this information, from using the trace sync flag to how to properly setup your Express application in production on the website: http://expressjs.com/en/advanced/best-practice-performance.html

@dougwilson thanks for the detailed reply!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Domiii picture Domiii  路  3Comments

HafidAbnaou picture HafidAbnaou  路  3Comments

jefflage picture jefflage  路  4Comments

haider0324 picture haider0324  路  3Comments

zackarychapple picture zackarychapple  路  3Comments