Why does the initial call to NSAttributedString with an HTML string take over 100 times longer than subsequent calls?

此生再无相见时 提交于 2019-11-28 05:54:39
Johannes Fahrenkrug

That's a really good question. It turns out that (at least for me) it is always slower the first time I call the method, no matter if the debugger is attached or not. Here is why: The first time you parse an HTML-attributed string, iOS loads a whole JavaScriptCore engine and WebKit into memory. Watch:

The first time we run the method (before parsing the string) only 3 threads exist:

After the string is parsed, we have 11 threads:

Now the next time we run the method, most of those web-related threads are still in existence:

That explains why it's slow the first time and fast thereafter.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!