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

JS 代码运行性能优化技巧 #208

Open
hughfenghen opened this issue Sep 13, 2024 · 0 comments
Open

JS 代码运行性能优化技巧 #208

hughfenghen opened this issue Sep 13, 2024 · 0 comments

Comments

@hughfenghen
Copy link
Owner

hughfenghen commented Sep 13, 2024

首先,代码简洁易懂通常更重要,性能优化应在明确性能瓶颈后再开始优化;
其次,系统性能问题往往是 DOM 操作IO 操作(文件读写、网络请求)、内存大量分配占用导致,性能问题应优先往这些方向排查。

当你的项目确实需要消耗大量计算资源(如 音视频、游戏、大量数据处理),有许代码被高频执行(如 十万次以上的循环)

可参考这篇文章中提到的技巧,进行代码运行方面的优化。
Optimizing Javascript for fun and for profit

0. Avoid work 避免多余的工作
1. Avoid string comparisons 避免字符串比较
2. Avoid different shapes 避免不同形状
3. Avoid array/object methods 避免一些数组/对象方法
4. Avoid indirection 避免间接访问
5. Avoid cache misses 避免缓存穿透
6. Avoid large objects 避免大型对象
7. Use eval 小心地使用 eval
8. Use strings, carefully 小心使用字符串
9. Use specialization 逻辑分支优化
10. Data structures 数据结构
11. Benchmarking 基准测试
12. Profiling & tools 分析和工具
Final notes 最后的笔记

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

No branches or pull requests

1 participant