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

[g] 使用轻量级的 tapable 替代 #970

Closed
xiaoiver opened this issue May 4, 2022 · 2 comments
Closed

[g] 使用轻量级的 tapable 替代 #970

xiaoiver opened this issue May 4, 2022 · 2 comments
Assignees
Labels

Comments

@xiaoiver
Copy link
Contributor

xiaoiver commented May 4, 2022

tapable 对于浏览器环境支持度并不好,例如在 vite 中直接使用会报错,需要在构建工具中进行配置:
#947

另外它体积也不小,我们需要一个轻量化的流程管理替代实现。
https://github.com/funnyecho/hamon

Codesandbox UMD:
https://codesandbox.io/s/yi-umd-xing-shi-shi-yong-g-701x5?file=/index.js
Codesandbox NPM:
https://codesandbox.io/s/yi-npm-module-xing-shi-shi-yong-g-wjfux?file=/index.js

@xiaoiver xiaoiver self-assigned this May 4, 2022
xiaoiver added a commit that referenced this issue May 5, 2022
* Publish

 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]

* Publish

 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]
 - @antv/[email protected]

* publish: v5.0.22

* feat: support federated touch event #936

* fix: replace tapable with a lite implementation #970

* fix: account for empty changedTouches

Co-authored-by: yuqi.pyq <[email protected]>
@xiaoiver xiaoiver closed this as completed May 6, 2022
@hustcc
Copy link
Member

hustcc commented May 6, 2022

使用 hamon 替换之后可以节省多少大小?另外这个包靠谱吗? @xiaoiver

@xiaoiver xiaoiver reopened this May 9, 2022
@xiaoiver
Copy link
Contributor Author

xiaoiver commented May 9, 2022

tapable 在 hook 执行多次的场景下性能提升很明显。

下图为使用 tapable 替代实现的执行效果,场景为 2w 个旋转的 Circle,可以看出 render 这个 hook 连续执行 2w 次,虽然每次耗时不高,但累积起来就会导致帧率明显下降(50 fps -> 12 fps):
截屏2022-05-09 上午11 34 46

而使用 tapable 后,几乎看不到这种累积的耗时:
截屏2022-05-09 下午4 12 33

如果不考虑大量连续调用的场景,确实没必要使用 tapable。但正如 webpack 作者在这个 issue 中所写,采用 new Function 静态编译后在这样的场景下的确能带来非常明显的提升效果:
ISSUE:webpack/tapable#162

另一个担忧是 tapable 是否只适合在 Node 端运行,而不适合浏览器端。个人认为还是得根据场景而定,如果需要流程管理而恰好又存在大量连续调用的场景,那 tapable 确实很合适。

之前 tapable 确实有使用箭头函数导致无法在 ie11 中运行的问题,但作者修复了该问题:
https://github.com/webpack/tapable/pull/151/files

ie11 兼容性验证:#978

@xiaoiver xiaoiver closed this as completed May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants