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
Improve performances #479
Improve performances #479
Conversation
Codecov Report
@@ Coverage Diff @@
## master #479 +/- ##
==========================================
- Coverage 100% 98.17% -1.83%
==========================================
Files 1 1
Lines 173 219 +46
==========================================
+ Hits 173 215 +42
- Misses 0 4 +4
Continue to review full report at Codecov.
|
@jxnblk are we ready to merge? |
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 for the delay! It's been a busy week 😬 This is looking good! I left some comments, and I'm happy to help out with some of these changes. I don't think you needed to close the previous PR and open a new one, so feel free to keep all the work in this one from now on. I did start a couple branches to separate the rollup config, but they might have conflicts now (see https://github.com/styled-system/styled-system/tree/smooth-perf-only & https://github.com/styled-system/styled-system/tree/smooth-rollup)
If you don't have time to tackle some of these changes, we can merge this into another working branch to continue forward
package.json
Outdated
"sideEffects": false, | ||
"scripts": { | ||
"prepare": "mkdirp dist && npm run build:cjs && npm run build:esm", | ||
"prepare": "rollup -c", |
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 should still be separated into a separate PR before landing
test/index.js
Outdated
}) | ||
}) | ||
// Impossible to ensure, due to perf issues | ||
// test('long form prop trumps aliased props', t => { |
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 commented code should be removed
test('parses object values', t => { | ||
const style = width({ | ||
width: { | ||
_: '100%', | ||
2: '50%', | ||
0: '100%', |
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.
If the _
key no longer works, this would mean a breaking change. Is there anyway to support the current functionality and plan for changing this in v5?
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.
In fact, the previous behaviour was not correct for me. An object was like an array:
// previous behaviour
{ _: '100%', 2: '50%' } // ['100%', '50%']
// current behaviour
{ _: '100%', 2: '50%' } // [, , '50%']
For me it is the correct and the expected behaviour, it is more a bug fix than a breaking change.
_: '100%', | ||
2: '50%', | ||
0: '100%', | ||
1: '50%', |
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.
The 2
key was used to demonstrate skipping a breakpoint. Can this change be reverted?
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.
See previous comment.
test/styles.js
Outdated
@@ -11,7 +11,7 @@ import { | |||
textStyle, | |||
colorStyle, | |||
borders, | |||
} from '../src' | |||
} from '../src/index' |
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.
nb: this change is unnecessary
src/index.js
Outdated
@@ -398,39 +487,39 @@ export const size = mapProps(props => ({ | |||
|
|||
export const verticalAlign = style({ prop: 'verticalAlign' }) | |||
|
|||
// flexbox | |||
// Flexboxes |
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.
// Flexboxes | |
// flexbox |
src/index.js
Outdated
export const flexDirection = style({ prop: 'flexDirection' }) | ||
export const flex = style({ prop: 'flex' }) | ||
export const justifySelf = style({ prop: 'justifySelf' }) | ||
export const alignSelf = style({ prop: 'alignSelf' }) | ||
export const order = style({ prop: 'order' }) | ||
|
||
// grid | ||
// Grid |
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.
// Grid | |
// grid |
src/index.js
Outdated
|
||
// variants | ||
// Variants |
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.
// Variants | |
// variants |
.npmignore
Outdated
CODE_OF_CONDUCT.md | ||
/* | ||
!/dist/**/*.js | ||
!/props.js |
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.
nb: personally I prefer not using negation for the ignore files
@@ -0,0 +1,688 @@ | |||
"use strict"; |
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.
Since this is copypasta dist code from the current version, I don't think this should be checked in
Following styled-system#444, I bring perf improvements from @smooth-ui/system into styled-system. The goal is to make this library the best one and the universal one. What have changed? - I switched to the core of @smooth-ui/system, more performant especially with multiple compose. Composition is now flat, it means you can compose 10 times and it will not be slower. We are probably in O(n), where "n" is the number of props. - I switched to rollup in order to optimize build, provide umd and improve tree shaking What are the breaking changes? - We now rely on the order of props. ES2015 is here and we can rely on it, see this tweet for context: https://twitter.com/ianstormtaylor/status/1115680037875752963. - Object keys or array keys have now equivalent parsing
e34dab9
to
3d671b3
Compare
Hello @jxnblk, I made the changes and I rebased. One test is not passing, the merge of variant, it was not part of the library initially. Also using your merge method instead of the deepmerge package makes a significant less of perf (according to benchmark). At start, when I come with this PR, I wanted to migrate Smooth UI System to styled-system. But I think it would not be possible, even if the philosophy is very close, we are not going in the same direction. There is a lot of points where we disagree:
Also, performance seems to not be something very important for you since a lot of other stuff was implemented and merged before this PR. I try to keep up with rebase but it is difficult (eg. the compose of variant). I understand your choices, but there are different from mines. So I think we can share the same "theming specification" but I will not use styled-system in Smooth UI or in my projects. I use it professionally, and I have my own roadmap, I can't stick to yours sorry. Thank you for your time, I hope my contribution helped you! |
@neoziro I'd really love to figure out how to get this landed, and I'd appreciate some patience here. This is a substantial PR and like any large code change, I expect it to take longer than some of the other smaller PRs that have been merged in. I can chip in to help with parts that you aren't interested in working on, but it sounds like maybe this PR's base should change to a As for the requested changes, you originally proposed a performance refactor, but also chose to include changes to the build and file structure – and are proposing changing the testing library as well. I'm not opposed to these changes, but they weren't discussed beforehand and make this PR harder to evaluate. I need to make sure changes in v4 do not break for the current users of this library, and I hope you can understand where I'm coming from here |
@jxnblk yeah sorry for including these changes, it was not part of perf issue. I think it is going to slow for me, anyway I could continue to submit issues and changes. About the PR, I don’t have time to invest more on it, but the core is here, feel free to iterate on it! Thanks for your time and your patience 🙏 |
Going to close this out since it seems like it's not moving forward. Thanks again for all the work on this and sorry this PR didn't work out. Hopefully we can collaborate in the future, and I'll definitely be taking some inspiration from this for the next version of styled-system |
@jxnblk no problem. You have the PR for history with the flattening of props in compose. It is the key for keep perf constants with several composes. Always happy to help! Thanks for this great library! |
Following #444, I bring perf improvements from @smooth-ui/system into styled-system.
The goal is to make this library the best one and the universal one.
What have changed?
especially with multiple compose. Composition is now flat, it means you
can compose 10 times and it will not be slower. We are probably in O(n),
where "n" is the number of props.
improve tree shaking
What are the breaking changes?
it, see this tweet for context: https://twitter.com/ianstormtaylor/status/1115680037875752963.
See #470 for all history and original code.