Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

net: Avoid tickDepth warnings on small writes #4676

Closed
wants to merge 1 commit into from

Conversation

isaacs
Copy link

@isaacs isaacs commented Jan 28, 2013

Stumbled upon this running a benchmark that was (incorrectly) doing a very small write in the callback of a very small write.

Since the write was small, it was entirely flushed, and the callback was called on nextTick by the Stream.Writable class (so as to prevent a "sometimes-sync" API).

However, the net.Socket class calls its _write callback synchronously when the chunk was entirely flushed, leading to a tickDepth warning.

Synchronous write streams can still trigger the tickDepth warning, but at least we should not cause this in net.Socket, and the alternative is a stack overflow. (Another alternative way to solve this would be for net.Socket to always defer its write cb, but that is giving up a significant optimization.)

Also, this exposes process.tickDepth as a read-only property, which is pretty useful.

@isaacs
Copy link
Author

isaacs commented Jan 28, 2013

Added as a plain-old-property. Doesn't seem to degrade performance of net-pipe.js as far as I can tell.

Always defer the _write callback.  The optimization here was only
relevant in some oddball edge cases that we don't actually care about.

Our benchmarks confirm that just always deferring the Socket._write cb
is perfectly fine to do, and in some cases, even slightly more
performant.
@isaacs
Copy link
Author

isaacs commented Jan 29, 2013

Removed the tickDepth exposure, in favor of a simpler fix in lib/net.js

@bnoordhuis
Copy link
Member

Much better! :-)

@othiym23
Copy link

tickDepth is a useful data point for instrumentation; is there a way it could make a reappearance later, perhaps as process._tickDepth?

@isaacs
Copy link
Author

isaacs commented Jan 29, 2013

@othiym23 All we really need is someone to want it. So, sure. Why not?

@isaacs isaacs closed this Jan 29, 2013
@isaacs
Copy link
Author

isaacs commented Jan 29, 2013

(This is landed on 02f7d1b)

@isaacs
Copy link
Author

isaacs commented Jan 29, 2013

@othiym23 That is, patch welcome.

@othiym23
Copy link

Noted!

@isaacs
Copy link
Author

isaacs commented Jan 29, 2013

For posterity: this was reverted in bda45a8. Breaks a test, and the edge case it supports is not all that relevant.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants