Chrome开发者工具性能分析结果中的侦听器 [英] Listeners in Chrome dev tools' performance profiling results

查看:189
本文介绍了Chrome开发者工具性能分析结果中的侦听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用Chrome开发人员工具对React应用进行性能分析,并且发现Listener的数量呈线性增长.看一下下面的截图. Listeners是橙色的.

I have been profiling a React app using Chrome dev tools and I've discovered a linearly increasing Listener count. Take a look at the screenshot below. The Listeners are in orange.

我将其范围缩小到p标签内的一个简单的倒计时值.剩余时间使用setInterval函数每1000毫秒生成一次,然后在p标记内进行格式化和呈现.

I narrowed it down to a simple countdown value render inside p tags. The remaining time is generated using setInterval function every 1000ms and then formatted and rendered inside the p tags.

我使用create-react-app创建了一个简单的React应用,并修改了App.js的App组件中的代码以每秒更新Date.now()的值,当我在其上运行探查器时,我得到了相同的结果结果.

I created a simple React app using create-react-app and modified the code inside the App.js's App component to update the value of Date.now() every second, and when I ran the profiler on it, I got the same result.

class App extends Component {
  state = {
    text: '',
  };

  loop() {
    this.setState({ text: Date.now() });
  }

  componentWillMount() {
    this.timer = setInterval(this.loop.bind(this), 1000);
  }

  componentWillUnmount() {
    clearInterval(this.timer);
  }

  render() {
    return (
      <div className="App">
        <p>{this.state.text}</p>
      </div>
    );
  }
}

export default App;

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆