-
Notifications
You must be signed in to change notification settings - Fork 187
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
Add minify global function to force style names minification #291
Conversation
Hey @Soreine, Thanks for the PR! Mind signing our Contributor License Agreement? When you've done so, go ahead and comment Yours truly, |
|
CLA signature looks good 👍 |
const StyleSheet = { | ||
create(sheetDefinition /* : SheetDefinition */) { | ||
return mapObj(sheetDefinition, ([key, val]) => { | ||
const stringVal = JSON.stringify(val); | ||
return [key, { | ||
_len: stringVal.length, | ||
_name: process.env.NODE_ENV === 'production' ? | ||
_name: shouldMinify() ? |
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.
With the previous version of this code, the conditional will end up being minified out in production, which gives us a small performance boost. Switching this to a runtime check will affect performance some amount.
It is probably a pretty small hit, but given that this code is in a pretty performance-sensitive path, it is definitely worth profiling the fully simplified version (e.g. _name: hashString(stringVal)
) against this version in real-world scenarios so we at least understand what the performance impact of this change is.
Can you do this profiling and post your findings on this PR?
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.
That's interesting... Do you have ready to use profilers ?
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 that I am aware of. I think to try this out, it would probably be best to use npm link
in a project that is setting the NODE_ENV
environment variable to production and minifying it out properly (e.g. in conjunction with webpack's DefinePlugin).
Update: Maybe another approach would be to measure the number of times this code path is executed in a real-case scenario, then make a separate benchmark that measures the performance of the compiled equivalent of |
I went ahead and ran some benchmarks for this. I went ahead and used the same benchmarks that react-native-web has set up. I made 1 change to the benchmark for Aphrodite. I moved All measurements in Current
Fork No Changes
Fork minify(true)
Fork minify(false)
There is only a slight difference between each scenario. My guess is if I ran the benchmark more times for each they would end up much closer results. I do not think that having 1 more if statement will really impact performance much, especially inside the |
@Soreine this seems to fail tests in CI after merging. https://travis-ci.org/Khan/aphrodite/builds/341685191 Any chance you can take a look and open a PR with a fix? |
@lencioni yes, sir. |
@lencioni Any chance to have this released as an npm tag? Or this library is not maintained anymore? |
@Kerumen this library is still maintained :) I think they just forgot, are busy or are waiting on something |
@Soreine The latest release was last October (https://github.com/Khan/aphrodite/releases). |
Another release is coming soon I believe. I think the maintainers are just waiting for #300 to go in and then a major release will be created. |
@Kerumen I hope to publish a release soon. This library is maintained and the release has not been forgotten. The next release will be a major version bump, so I want to make sure we get in all of the in-flight breaking changes before we publish. |
Fix #288
This exports a global function
minify
that can be called to control the minification of style names, independently of theNODE_ENV
environment value.Call
minify(false)
before usingStyleSheet.create
to never minify style names. Callminify(true)
to always minify style names. Defaults to the current behavior of minifying only ifprocess.env.NODE_ENV === 'production'
.