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
Skip assertDoc calls in production #3268
Conversation
If we never We might want to offload this kind of check to a type checker like flow or etc instead of taking the runtime hit (static type checking instead). But of course, adding flow could make things more overwhelming for new contributors. Not sure how often new contributors make changes to the doc printer though (I suspect rarely). |
I'm not sure I understand this correctly. But if I did, I think we're not covered, since the case for I was wondering what would be the downside of skipping the |
Sorry that I wasn't clear, but yes, you understood correctly. I like the idea of skipping assertDoc in production. Let's do that instead of special-casing fill. |
src/doc-builders.js
Outdated
throw new Error( | ||
"Value " + JSON.stringify(val) + " is not a valid document" | ||
); | ||
if (process.env.NODE_ENV === "production") { |
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 be !==
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.
🙄 sorry about that
@suchipi Looks like just calling the function is expensive enough :( (or the |
I had to wrap each call with the if and add the replace in rollup build script to remove them from the dist file (optional but skips an It's a bit ugly that bunch of ifs lying around but I think it's worth the benefit. We could change them with a Let me know what you think! |
src/doc-builders.js
Outdated
@@ -2,7 +2,7 @@ | |||
|
|||
function assertDoc(val) { | |||
/* istanbul ignore if */ | |||
if (process.env.NODE_ENV === "production") { | |||
if (process.env.NODE_ENV !== "production") { |
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.
Not sure this is the right way of doing it, a lot of people will run prettier in "development"
env.
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.
@azz I updated the PR, can you check again?
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.
To clarify, when building the bundle, we will replace that check with "production"
to remove that entirely
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.
Oh, right. Cool.
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 mind the ifs; I think people are pretty used to seeing process.env.NODE_ENV
in code these days, compared to something more "magic" like __DEV__
.
Context: #3263 (comment)
When
printDocToString
callsfill
, it's not necessary to callassertDoc
for all of the remaining elements since they already checked when the doc was originally created (somewhere inprintAstToDoc
).