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

Code optimizations #1150

Merged
merged 13 commits into from
May 5, 2021
Merged

Code optimizations #1150

merged 13 commits into from
May 5, 2021

Conversation

shuding
Copy link
Member

@shuding shuding commented May 2, 2021

Did a couple of code optimizations in this PR for better structure and code reusing. Also handles the case that undefined is manually set to another value*.

As a result, here's the size of the built dist/index.js with this PR:

  • Before: 12072B
  • After: 11361B

*Although Rollup handles it automatically by changing it to void 0, it's great to have it in the source code. This trick also makes the built file smaller.

@codesandbox-ci
Copy link

codesandbox-ci bot commented May 2, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit ed3ba4d:

Sandbox Source
SWR-Basic Configuration
SWR-States Configuration
SWR-Infinite Configuration
SWR-SSR Configuration

@shuding shuding requested a review from huozhi May 2, 2021 17:44
@shuding shuding marked this pull request as ready for review May 4, 2021 12:47
@shuding shuding requested a review from pacocoursey as a code owner May 4, 2021 12:47
src/env.ts Show resolved Hide resolved
src/libs/hash.ts Show resolved Hide resolved
src/config.ts Outdated Show resolved Hide resolved
@@ -24,6 +25,10 @@ import {

type Revalidator = (...args: any[]) => void

// Generate strictly increasing timestamps.
let __timestamp = 0
Copy link
Member

@huozhi huozhi May 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you feel it's okay to start timestamp from 1 to avoid some issue like !now() ? not blocking

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 (where are we using !now() btw?)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we used to have this issue in #1075

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just checked again, we are using const now = () => ++__timestamp so it will be starting from 1 I think.

@shuding shuding merged commit 10c0080 into master May 5, 2021
@shuding shuding deleted the micro-optimizations-2 branch May 5, 2021 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants