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

using utility methods for value type checking #16318

Merged
merged 6 commits into from
Jan 4, 2022
Merged

using utility methods for value type checking #16318

merged 6 commits into from
Jan 4, 2022

Conversation

pissang
Copy link
Contributor

@pissang pissang commented Jan 4, 2022

Brief Information

This pull request is in the type of:

  • bug fixing
  • new feature
  • others

What does this PR do?

This PR replaces all typeof xxx === 'string', typeof xxx === 'number', typeof xxx === 'function' to isString, isNumber, isFunction utility methods to have neater codes. It reduces 1565 bytes in total after minimized.

And the related benchmark about this change: https://jsbench.me/yskxzuqb9t/1 . Changing inline code to function call won't have performance drop. The interesting thing is some optimizations we did before like caching the typeof result in https://github.com/apache/echarts/blob/master/src/data/helper/dataValueHelper.ts#L158 will lead to worse performance on the chrome.

This PR also removes circular dependency introduced in #16300

@echarts-bot
Copy link

echarts-bot bot commented Jan 4, 2022

Thanks for your contribution!
The community will review it ASAP. In the meanwhile, please checkout the coding standard and Wiki about How to make a pull request.

The pull request is marked to be PR: author is committer because you are a committer of this project.


const mathLog = Math.log;
export const mathLog = Math.log;

Copy link
Member

@plainheart plainheart Jan 4, 2022

Choose a reason for hiding this comment

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

I ever thought if it may be slightly better to extract all the mathematic functions to a common helper. Any idea? If it's feasible, that'll be a huge job.

Copy link
Contributor Author

@pissang pissang Jan 4, 2022

Choose a reason for hiding this comment

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

Removed this export.

I ever thought if it may be slightly better to extract all the mathematic functions to a common helper

I'm not sure about it. It will be helpful if some mathematic functions needs to be polyfilled(e.g. Math.hypot) or implentated. But If we only export the methods that exits in the Math ns. It seems to be too tricky to reduce the code size.

Copy link
Contributor Author

@pissang pissang Jan 10, 2022

Choose a reason for hiding this comment

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

Copy link
Member

@plainheart plainheart Jan 10, 2022

Choose a reason for hiding this comment

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

@pissang It should reduce some redundant Math, degree to radian, and other commonly used values like 2π, 1/2π to shrink the bundle size. But this may be insignificant.

src/coord/cartesian/Grid.ts Outdated Show resolved Hide resolved
src/coord/radar/Radar.ts Outdated Show resolved Hide resolved
@pissang pissang merged commit 3b6d01a into next Jan 4, 2022
@echarts-bot
Copy link

echarts-bot bot commented Jan 4, 2022

Congratulations! Your PR has been merged. Thanks for your contribution! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants