Skip to content

Provide a --warn-on-late-sync flag for tracing synchronous calls #1674

@benjamingr

Description

@benjamingr

What

io.js should provide a --warn-on-late-sync that would detect whenever a *Sync method has been called after the first full round of the event loop and emit a warning to stderr.

setTimeout(function(){
     fs.readFileSync("/foo/bar");
})
$ io.js file.js --warn-on-late-sync

Warning fs.readFileSync (file.js 3:7) called after a full turn of the event loop has completed. This may cause performance bottlenecks in your code (option --warn-on-late-sync). Please see http://iojs.org/... for more details.

Comments about semantics

  • Warnings are only emitted after a full turn of the event loop has happened.
  • Warnings are not emitted in case the process is terminating (that is, in process.on("exit" code)
  • Warnings are emitted to the stderr stream, preferably with a stack trace

    Why

This flag would be very useful at finding out performance bottlenecks of hidden *Sync calls and alerting users as well as hopefully explaining what they can do about it (switch to non-*Sync) methods.

Breaking changes

This issue contradicts #1665 by making it opt-in and not opt out, the benefit is that it enables a lot of what that issue enables without breaking any existing code or forcing users to do anything about it.

Future PoV

It can also be a start for a future --pedantic flag that warns against the most common performance pitfalls node servers have that can't be alerted from the userland.

(I opened this issue per @Fishrock123 's request of opening a separate issue)

I'm open to naming suggestions of course, I'd like this to be brought up in the TC to see if the committee doesn't find any implementation limitations or compelling reasons not to do this before any work is initiated. This is of course in addition to any comments being welcome on this issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions