The story that the performance increased by 9.26 times when the layout method of View was changed from AutoLayout to warm hand calculation.

prev

This article is the 15th day article of iOS Advent Calendar 2020. Yesterday, @zwtin said You should stop getting images with the thumbnail method of ALAsset.

disclaimer

There is no intention to recommend manual calculation, it is the content measured under special circumstances

Premise

--Lay out a UIScrollView with a contentView that is about 10 times the height of the screen --Case with a large number of views, such as calendar dates each consisting of UILabel

Changes

――The reason for the change is that it takes time to transition the screen. --As the title suggests, the code laid out with AutoLayout + UIStackView now calculates the frame on its own.

result

--The process that used to take 1.0038 seconds before the change is now 0.1084 seconds. --Measure the time from immediately after super.loadView () to immediately after super.viewDidLayoutSubviews () ――The average value of each executed 5 times alternately --The measurement environment is iPhone 12 Pro Max -(Originally, it was verified with iPhone 11 Pro, so it's a secret that "that? AutoLayout is relatively fast?")

――The solver of AutoLayout is excellent, and the difference update when a little change is made is strong, but after all, the optimization problem is solved at the first time, so if you can make a static decision, that's the impression.

Hierarchy comparison before and after the change

--Up to 7 levels of nesting from UIScrollView to the bottom layer are now flatly placed directly under UIScrollView.

In the first place

--In the first place, if you want to create a UIScrollView with such a contentSize, I think it is correct to use UICollectionView. ―― ~~ However, trying to do this kind of layout is troublesome ~~ ――If you want to display data for about 20 years, you may have to deal with it (but the specifications may evolve faster: smile :)

verification code

https://github.com/funnything/LayoutPerformanceDemo

Promotion

We publish an app on the App Store that incorporates the changes covered in this article. It is an app that allows you to make a habit of training to make a more natural and attractive smile by making a smile every day. Nowadays, the tension tends to drop due to the corona virus, and I hope it helps to raise your feelings even a little. Please use it if you like ~ Download on the App Store

next

Tomorrow is an article by @yum_fishing.

Recommended Posts

The story that the performance increased by 9.26 times when the layout method of View was changed from AutoLayout to warm hand calculation.
The story that ARM's processing performance of Open JDK was low
The story of making it possible to build a project that was built by Maven with Ant
[Java] The story that the expected array was not obtained by the String.split method.
Report an example of performance degradation that occurred when the argument Comparator of Arrays.sort was given by a lambda expression
I want you to put the story that the error was solved when you stabbed the charger in the corner of your head
The story of migrating from Paperclip to Active Storage
The version of Ruby that was installed by default on the Mac was referenced, not from rbenv