Skip to content

Commit

Permalink
[perf] optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
Siubaak committed Feb 7, 2024
1 parent a8551d6 commit cb15ccd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions docs/OPTIMIZATION.md
Expand Up @@ -20,7 +20,8 @@

## 第一次优化

优化项:原来每一行都yield出来再判断是否断点,改成先判断断点再yield出来,减少generator保存状态的性能消耗
优化项:
- 原来每一行都yield出来再判断是否断点,改成先判断断点再yield出来,减少generator保存状态的性能消耗

优化效果:
- 17.2ms (-26.5%)
Expand All @@ -30,7 +31,8 @@

## 第二次优化

优化项:每次checkIfBreak都需要调用Scope.updateCallFrame更新调用帧信息,而每次updateCallFrame被调用,都需要寻找最近的函数作用域,改成缓存最近的函数作用域,用空间换时间
优化项:
- 每次checkIfBreak都需要调用Scope.updateCallFrame更新调用帧信息,而每次updateCallFrame被调用,都需要寻找最近的函数作用域,改成缓存最近的函数作用域,用空间换时间

优化效果:
- 14.6ms (-37.6%)
Expand All @@ -40,10 +42,12 @@

## 第三次优化

优化项:原来一些临时变量声明在每个块级作用域中,改成全局声明,优化有限
优化项:
- 原来一些临时变量声明在每个块级作用域中,改成全局声明,优化有限
- 获取断点进行判断的时候,从直接获取改成先判断是否有断点再获取

优化效果:
- 14.5ms (-38%)
- 10ms (-9.9%)
- 6ms (-43.4%)
- 5.9ms (-44.3%)
- 2.8ms (-54.8%)
2 changes: 1 addition & 1 deletion src/index.js
Expand Up @@ -83,7 +83,7 @@ function checkIfBreak(debuggerId, breakpointId, lineNumber, columnNumber, scopeB
// 如果当前禁用了断点,那么继续执行
return;
}
const condition = Transformer.breakpointMap.get(breakpointId);
const condition = Transformer.breakpointMap.size && Transformer.breakpointMap.get(breakpointId);
if (!condition && ['stepInto', 'stepOver', 'stepOut'].indexOf(resumeOptions?.type) === -1) {
// 如果没有命中断点,并且不是单步调试,那么继续执行
return;
Expand Down

0 comments on commit cb15ccd

Please sign in to comment.