Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

perf: optimize update performance #1777

Merged
merged 1 commit into from
Dec 7, 2021

Conversation

1198994985
Copy link
Contributor

node调用update方法时,this.parent!.path会重复计算

@codesandbox-ci
Copy link

codesandbox-ci bot commented Dec 6, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 86f9e75:

Sandbox Source
one Configuration

@watsonhaw5566
Copy link
Contributor

node调用update方法时,this.parent!.path会重复计算

代码里做了parentPath的抽取变量,这样优化可以减少for循环的重复读取吗?

@1198994985
Copy link
Contributor Author

1198994985 commented Dec 6, 2021

node调用update方法时,this.parent!.path会重复计算

代码里做了parentPath的抽取变量,这样优化可以减少for循环的重复读取吗?

访问path会调用get path()这个方法,提取出来会减少path的获取,按理来说会优化一些性能

get path() {
const dataPath: string[] = [];
const parents = [];
let parent = this.parent;

while (parent) {
  parents.unshift(parent);
  parent = parent.parent;
}

for (let i = 0; i < parents.length; i++) {
  const child = parents[i + 1] || this;

  if (RuntimeOptions.get('platform') === 'ali') {
    dataPath.push('children');
    dataPath.push(child.index.toString());
  } else {
    dataPath.push('nodes');
    dataPath.push(child.id.toString());
  }
}

return dataPath;

}

@watsonhaw5566
Copy link
Contributor

watsonhaw5566 commented Dec 6, 2021

@1198994985 容我想想需要怎么测试,兄die在钉钉群里面没。可否交流一波。我们也准备写一下字节小程序。

@1198994985
Copy link
Contributor Author

1198994985 commented Dec 6, 2021

@1198994985 容我想想需要怎么测试,兄die在钉钉群里面没。可否交流一波。我们也准备写一下字节小程序。

没在,钉钉群是哪个,我加一下 @watsonhaw5566

@watsonhaw5566
Copy link
Contributor

watsonhaw5566 commented Dec 6, 2021

@1198994985 容我想想需要怎么测试,兄die在钉钉群里面没。可否交流一波。我们也准备写一下字节小程序。

没在,钉钉群是哪个,我加一下 @watsonhaw5566

钉钉群号: 34935625
或者扫码

@1198994985
Copy link
Contributor Author

@1198994985 容我想想需要怎么测试,兄die在钉钉群里面没。可否交流一波。我们也准备写一下字节小程序。

没在,钉钉群是哪个,我加一下 @watsonhaw5566

钉钉群号: 34935625 或者扫码

搜1198994985,那个人就是我 @watsonhaw5566

@codecov
Copy link

codecov bot commented Dec 6, 2021

Codecov Report

Merging #1777 (86f9e75) into master (b119d5d) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1777   +/-   ##
=======================================
  Coverage   90.27%   90.28%           
=======================================
  Files         386      386           
  Lines        4711     4712    +1     
  Branches      716      681   -35     
=======================================
+ Hits         4253     4254    +1     
  Misses        449      449           
  Partials        9        9           
Impacted Files Coverage Δ
packages/remax-runtime/src/VNode.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b119d5d...86f9e75. Read the comment docs.

@yesmeck yesmeck merged commit 0e0a6b5 into remaxjs:master Dec 7, 2021
@1198994985
Copy link
Contributor Author

1198994985 commented Dec 7, 2021 via email

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

Successfully merging this pull request may close these issues.

None yet

3 participants