GithubHelp home page GithubHelp logo

你在第一次访问的时候改变了初始化的消耗,产生了副作用,这会让优化性能变得困难(以及测试) about objc-zen-book-cn HOT 1 OPEN

oa414 avatar oa414 commented on August 16, 2024
你在第一次访问的时候改变了初始化的消耗,产生了副作用,这会让优化性能变得困难(以及测试)

from objc-zen-book-cn.

Comments (1)

oa414 avatar oa414 commented on August 16, 2024

我的理解是这样:

原来对象创建的时候,可能在 init 系列方法就做了一些初始化工作(打开文件,绑定端口,初始化成员变量等等),如上面的代码的例子是初始化 _dateFormatter。使用 lazy initialization 的时候,只有你第一次调用的时候 -dateFormatter 方法,才会做这些初始化的工作。

假如这些初始化工作很消耗性能,或者有一些问题,那么这些问题在对象初始化的时候就能被创建出来。但是使用 lazy initialization 后,实际的初始化工作是在后续某个执行过程中,才会做这些操作。那么你去测试性能或者用 Instrument 这些工具,就要去追踪后面的执行过程什么时候会调用到这个地方了,而不是单纯看哪个对象创建的时候比较耗时。

from objc-zen-book-cn.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.