Comments (6)
翻到本次精读的译文贴出来:
https://zhuanlan.zhihu.com/p/28225985
from weekly.
try catch 对性能的影响忽略不计
try catch 非常有用,特别在 node 端更是一个常规操作。前端框架也越来越多采用了异常捕获的方式,结合 async await 让代码组织得更加优雅,详细可以看我的这篇博文 统一异常捕获。react mixins 也喜欢 try 住 render 方法,包括 16 版本自动 try 住了所有 render,try catch 可谓无处不在。
node 8 版本之后 try 内部函数性能损耗可以忽略不计。
但是当前版本仍然存在安全隐患,将 这里的代码 拷贝到 chrome 控制台,当前页面会进入无限死循环。
此例子对 try catch 块做了大量循环,官方说法是在某些代码组合情况下陷入无限优化循环。
from weekly.
有个疑问, 这个精读是所有人都可以参与, 还是说指定人才能回答?
from weekly.
@mynane 所有人都可以参加
from weekly.
解决 delete 性能问题
js 正在变得越来越简单,该 delete 的地方也不会犹豫是否写成 undefined,以提升性能为代价降低代码可读性了。
arguments 转数组性能已不是问题
在 node8.3 版本及以上,该使用拓展运算符获取参数,不但没有性能问题,可读性也大大提高,结合 ts 时也能得到类型支持。
bind 对性能影响可以忽略
但是在 react 中副作用仍需警惕。由于 ui 组件复用次数在大部分场景及其有限,强烈推荐使用箭头函数书写成员函数(在我的另一篇精读 This 带来的困惑 有详细介绍),而且在 node8 中,箭头函数的性能是最好的。
from weekly.
函数调用对性能影响越来越小
对函数调用优化的越来越好,不需要过于担心注释与空白、函数间调用对性能的影响.
32 64 位数字计算性能
node8 对超长数字计算性能还是较低,大概是 32 位数字性能的 2/3,所以尽量用字符串处理大数。
遍历 object
基本用法有 for in
Object.keys
Object.values
. 在 node8 中,for in
将变得更慢,但任然比其他两种方法快,所以,尽早取消不必要的优化。
创建对象
创建对象速度在 node8 得到极大提升,似乎是面向对象编程的福音。
多态函数的性能问题
当函数或者对象存在多种类型参数时,在 node8 中性能没什么优化,但单态函数性能大幅提升。所以尽量让对象内部属性单态是比较有用的,比如尽量不要对字符串数组 push
一个数字。
from weekly.
Related Issues (20)
- 【自荐开源】AI可视化SolidUI HOT 2
- 精读《自由 + 磁贴混合布局》
- 请假一次 🏳️
- 精读《自由布局吸附线的实现》
- 请假一次 HOT 1
- 精读《算法题 - 通配符匹配》
- 这里我想是对应的 '*' 不匹配任何字符? HOT 1
- 精读《算法题 - 统计可以被 K 整除的下标对数目》
- 精读《算法题 - 最小覆盖子串》
- 请假一次
- 精读《算法题 - 地下城游戏》
- 请假一次 HOT 6
- 精读《VisActor 数据可视化工具》
- 精读《算法题 - 编辑距离》
- 请假一次
- 精读《算法题 - 二叉树中的最大路径和》
- 休刊一段时间 HOT 8
- 真的牛逼,竟然检测有病毒
- 【开源自荐】基于nextjs14,良好的体验、响应式、编码设计,开源了C-Shopping开源电商平台 HOT 7
- 第二季准备开更,内容预告! HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from weekly.