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

记一次 Javascript 性能优化 #30

Open
OPY-bbt opened this issue Jan 19, 2020 · 1 comment
Open

记一次 Javascript 性能优化 #30

OPY-bbt opened this issue Jan 19, 2020 · 1 comment

Comments

@OPY-bbt
Copy link
Owner

OPY-bbt commented Jan 19, 2020

for (var i = 0; i < 8000; i++) {
   if (...) {
      glyph.path.commands.forEach();
   }
}
for (var i = 0; i < 8000; i++) {
   var commands = glyph.path.commands;
   if (...) {
      commands.forEach();
   }
}

这两段代码性能差了50倍。。

@OPY-bbt
Copy link
Owner Author

OPY-bbt commented Jan 19, 2020

看到源码里的这一句应该就明白了

Object.defineProperty(this, 'path', getPathDefinition(this, options.path));

关键是这种问题真的很难发现,这次发现是因为3D字的demo速度很快,但是同事放到项目中却很卡,经过仔细排查才发现问题。

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