-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid to log if the log is not set #776
Conversation
fastify.js
Outdated
@@ -26,6 +26,8 @@ const runHooks = require('./lib/hookRunner') | |||
|
|||
const DEFAULT_JSON_BODY_LIMIT = 1024 * 1024 // 1 MiB | |||
|
|||
function noop (anError, res) { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there's any reason for a no-op to have parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add the isAbstract
check also here?
Line 202 in 81b6e01
res._startTime = now() |
@delvedor yeah, |
fastify.js
Outdated
@@ -199,7 +203,9 @@ function build (options) { | |||
|
|||
req.log.info({ req }, 'incoming request') | |||
|
|||
res._startTime = now() | |||
if (!isAbstract) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use isAbstract === false
it should be faster.
Can you also paste the new benchmarks?
3662ea2
to
d4c577b
Compare
New bench:
this branch
I don't know if this bench are accurate or not. Is there someone that is able to confirm it? |
Last commit removes two listener: if the logger is abstract and the current context has no Lines 203 to 204 in 8aa6b1d
|
fastify.js
Outdated
@@ -206,8 +206,10 @@ function build (options) { | |||
if (isAbstract === false) { | |||
res._startTime = now() | |||
} | |||
res.on('finish', onResFinished) | |||
res.on('error', onResFinished) | |||
if (isAbstract === false || context.onResponse !== null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do the same for res._context = context
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
fastify.js
Outdated
res.on('error', onResFinished) | ||
if (isAbstract === false) { | ||
res._startTime = now() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might create some deopts and prevent some inlining if logging is indeed enable (which will be the majority of cases). Can you test if the throughput drops with logging enabled?
I fear that might be the case, as I've seen this happening when properties are added within an if
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't seen any drops.
NB: In the whole application isAbstract
is a constant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
fastify.js
Outdated
@@ -40,12 +42,14 @@ function build (options) { | |||
} | |||
|
|||
var log | |||
var isAbstract = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you make this variable name more precise? hasLogger
is a good one for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
fastify.js
Outdated
res.on('finish', onResFinished) | ||
res.on('error', onResFinished) | ||
if (isAbstract === false) { | ||
res._startTime = now() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can safely move res._startTime = now()
inside the if
below, since it is used only inside the onResponseCallback
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again, I would not touch this. The chances to have a change of shape is very high.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your suggestion is to remove all the if
checks inside this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no. Adding a property within an if is a clear strategy to cause deopts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@allevo any update on this? |
Tomorrow I'll update this PR
Il lun 26 feb 2018, 12:47 Matteo Collina <notifications@github.com> ha
scritto:
… @allevo <https://github.com/allevo> any update on this?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#776 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABAVrVXTmxeOnec9TfYBlOIUkN5eOaP-ks5tYpnlgaJpZM4SBjvX>
.
|
aa99ca6
to
9aa8789
Compare
rebased |
Can you please check if the improvement is still there? |
@mcollina Removing the call to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
loggerUtils.onResponseCallback
logs only if there's a loggerBench:
this branch:
master:
Can someone else confirm this improvement?
Checklist
npm run test
andnpm run benchmark