Skip to content
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

Use .slice() for all substring-ing #26677

Merged
merged 1 commit into from
Apr 19, 2023
Merged

Conversation

sophiebits
Copy link
Collaborator

@sophiebits sophiebits commented Apr 19, 2023

  • substr is Annex B
  • substring silently flips its arguments if they're in the "wrong order", which is confusing
  • slice is better than sliced bread (no pun intended) and also it works the same way on Arrays so there's less to remember

I'd be down to just lint and enforce a single form just for the potential compression savings by using a repeated string.

Originally posted by @sebmarkbage in #26663 (comment)

- substr is Annex B
- substring silently flips its arguments if they're in the "wrong order", which is confusing
- slice is better than sliced bread (no pun intended) and also it works the same way on Arrays so there's less to remember
@sophiebits sophiebits requested a review from sebmarkbage April 19, 2023 21:13
@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Apr 19, 2023
@sophiebits
Copy link
Collaborator Author

I at least skimmed all the changes. They're probably right.

@react-sizebot
Copy link

Comparing: c826dc5...0750c97

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.min.js = 164.67 kB 164.67 kB = 51.81 kB 51.81 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 168.43 kB 168.43 kB = 52.94 kB 52.93 kB
facebook-www/ReactDOM-prod.classic.js = 568.32 kB 568.32 kB = 100.61 kB 100.61 kB
facebook-www/ReactDOM-prod.modern.js = 552.06 kB 552.05 kB = 97.91 kB 97.91 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.development.js = 26.42 kB 26.36 kB = 6.94 kB 6.94 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.development.js = 26.42 kB 26.36 kB = 6.94 kB 6.94 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.development.js = 26.42 kB 26.36 kB = 6.94 kB 6.94 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js = 24.88 kB 24.82 kB = 6.49 kB 6.49 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js = 24.88 kB 24.82 kB = 6.49 kB 6.49 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.development.js = 24.88 kB 24.82 kB = 6.49 kB 6.49 kB
oss-experimental/react-client/cjs/react-client-flight.development.js = 22.90 kB 22.84 kB = 6.05 kB 6.05 kB
oss-stable-semver/react-client/cjs/react-client-flight.development.js = 22.90 kB 22.84 kB = 6.05 kB 6.05 kB
oss-stable/react-client/cjs/react-client-flight.development.js = 22.90 kB 22.84 kB = 6.05 kB 6.05 kB
facebook-relay/flight/ReactFlightNativeRelayClient-prod.js = 12.50 kB 12.46 kB = 3.23 kB 3.23 kB
facebook-www/ReactFlightDOMRelayClient-prod.classic.js = 12.44 kB 12.41 kB = 3.18 kB 3.18 kB
facebook-www/ReactFlightDOMRelayClient-prod.modern.js = 12.44 kB 12.41 kB = 3.18 kB 3.18 kB
oss-experimental/react-server-dom-webpack/umd/react-server-dom-webpack-client.browser.production.min.js = 9.76 kB 9.70 kB = 3.86 kB 3.86 kB
oss-stable-semver/react-server-dom-webpack/umd/react-server-dom-webpack-client.browser.production.min.js = 9.76 kB 9.70 kB = 3.86 kB 3.86 kB
oss-stable/react-server-dom-webpack/umd/react-server-dom-webpack-client.browser.production.min.js = 9.76 kB 9.70 kB = 3.86 kB 3.86 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.production.min.js = 9.52 kB 9.46 kB = 3.75 kB 3.75 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.production.min.js = 9.52 kB 9.46 kB = 3.75 kB 3.75 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.browser.production.min.js = 9.52 kB 9.46 kB = 3.75 kB 3.75 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.production.min.js = 7.28 kB 7.23 kB = 2.95 kB 2.95 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.production.min.js = 7.28 kB 7.23 kB = 2.95 kB 2.95 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.edge.production.min.js = 7.28 kB 7.23 kB = 2.95 kB 2.95 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.production.min.js = 7.21 kB 7.15 kB = 2.90 kB 2.90 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.production.min.js = 7.21 kB 7.15 kB = 2.90 kB 2.90 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.production.min.js = 7.21 kB 7.15 kB = 2.90 kB 2.90 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js = 6.84 kB 6.78 kB = 2.72 kB 2.71 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js = 6.84 kB 6.78 kB = 2.72 kB 2.71 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-client.node.unbundled.production.min.js = 6.84 kB 6.78 kB = 2.72 kB 2.71 kB
oss-experimental/react-client/cjs/react-client-flight.production.min.js = 6.30 kB 6.24 kB = 2.50 kB 2.49 kB
oss-stable-semver/react-client/cjs/react-client-flight.production.min.js = 6.30 kB 6.24 kB = 2.50 kB 2.49 kB
oss-stable/react-client/cjs/react-client-flight.production.min.js = 6.30 kB 6.24 kB = 2.50 kB 2.49 kB

Generated by 🚫 dangerJS against 0750c97

@sebmarkbage
Copy link
Collaborator

Yaas. Look at that gzip win!

@sophiebits
Copy link
Collaborator Author

sophiebits commented Apr 19, 2023

0.01kB saved! 🔥

@sophiebits sophiebits merged commit 767f522 into facebook:main Apr 19, 2023
@sophiebits
Copy link
Collaborator Author

Actually, saving 4 bytes on gzip -9 is pretty good considering it's just one callsite in that bundle.

hoxyq added a commit that referenced this pull request Apr 20, 2023
Full list of changes:
* Use .slice() for all substring-ing
([sophiebits](https://github.com/sophiebits) in
[#26677](#26677))
* cleanup[devtools]: remove named hooks & profiler changed hook indices
feature flags ([hoxyq](https://github.com/hoxyq) in
[#26635](#26635))
* chore[devtools/release-scripts]: update messages / fixed npm view com…
([hoxyq](https://github.com/hoxyq) in
[#26660](#26660))
* (patch)[DevTools] bug fix: backend injection logic not working for
undocked devtools window ([mondaychen](https://github.com/mondaychen) in
[#26665](#26665))
* use backend manager to support multiple backends in extension
([mondaychen](https://github.com/mondaychen) in
[#26615](#26615))
kassens pushed a commit that referenced this pull request Apr 21, 2023
- substr is Annex B
- substring silently flips its arguments if they're in the "wrong order", which is confusing
- slice is better than sliced bread (no pun intended) and also it works the same way on Arrays so there's less to remember

---

> I'd be down to just lint and enforce a single form just for the potential compression savings by using a repeated string.

_Originally posted by @sebmarkbage in #26663 (comment)
kassens pushed a commit that referenced this pull request Apr 21, 2023
Full list of changes:
* Use .slice() for all substring-ing
([sophiebits](https://github.com/sophiebits) in
[#26677](#26677))
* cleanup[devtools]: remove named hooks & profiler changed hook indices
feature flags ([hoxyq](https://github.com/hoxyq) in
[#26635](#26635))
* chore[devtools/release-scripts]: update messages / fixed npm view com…
([hoxyq](https://github.com/hoxyq) in
[#26660](#26660))
* (patch)[DevTools] bug fix: backend injection logic not working for
undocked devtools window ([mondaychen](https://github.com/mondaychen) in
[#26665](#26665))
* use backend manager to support multiple backends in extension
([mondaychen](https://github.com/mondaychen) in
[#26615](#26615))
EdisonVan pushed a commit to EdisonVan/react that referenced this pull request Apr 15, 2024
- substr is Annex B
- substring silently flips its arguments if they're in the "wrong order", which is confusing
- slice is better than sliced bread (no pun intended) and also it works the same way on Arrays so there's less to remember

---

> I'd be down to just lint and enforce a single form just for the potential compression savings by using a repeated string.

_Originally posted by @sebmarkbage in facebook#26663 (comment)
EdisonVan pushed a commit to EdisonVan/react that referenced this pull request Apr 15, 2024
Full list of changes:
* Use .slice() for all substring-ing
([sophiebits](https://github.com/sophiebits) in
[facebook#26677](facebook#26677))
* cleanup[devtools]: remove named hooks & profiler changed hook indices
feature flags ([hoxyq](https://github.com/hoxyq) in
[facebook#26635](facebook#26635))
* chore[devtools/release-scripts]: update messages / fixed npm view com…
([hoxyq](https://github.com/hoxyq) in
[facebook#26660](facebook#26660))
* (patch)[DevTools] bug fix: backend injection logic not working for
undocked devtools window ([mondaychen](https://github.com/mondaychen) in
[facebook#26665](facebook#26665))
* use backend manager to support multiple backends in extension
([mondaychen](https://github.com/mondaychen) in
[facebook#26615](facebook#26615))
bigfootjon pushed a commit that referenced this pull request Apr 18, 2024
- substr is Annex B
- substring silently flips its arguments if they're in the "wrong order", which is confusing
- slice is better than sliced bread (no pun intended) and also it works the same way on Arrays so there's less to remember

---

> I'd be down to just lint and enforce a single form just for the potential compression savings by using a repeated string.

_Originally posted by @sebmarkbage in #26663 (comment)

DiffTrain build for commit 767f522.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants