IOS Fish weekly, mainly share the experience and lessons encountered in the development process, high-quality blog, high-quality learning materials, practical development tools, etc. The weekly warehouse is here: github.com/zhangferry/… If you have a good content recommendation, you can submit it through the way of issue. You can also apply to be our resident editor to maintain the weekly. Also can pay attention to the public number: iOS growth road, backstage click into the group communication, contact us, get more content.

This topic

@Zhangferry: Hello everyone, iOS Fishing Weekly has been released to the 16th issue unconsciously! In order to understand people’s thoughts and suggestions on the weekly, we conducted a questionnaire survey some time ago. The results of the questionnaire were generally in line with the expected assumptions, and we also adopted some good suggestions. So last week we stopped a new issue to prepare for the new content, this content is the first issue after the revision. If you have any good ideas and suggestions in the future, you can continue to give feedback to us. I hope that Fish Weekly can make progress together with you

Tweaks: Removed bugs, programming concept modules, and added topics and interview parsing.

Let’s focus on the function of the topic module of this issue. After investigating well-known weekly newspapers in various fields, we found a unique weekly newspaper that matches our temperament: Ruan Yifeng’s Technology Lovers weekly. Ruan yifeng’s weekly is special because it not only talks about science and technology, but also has weekly topics to talk about some thoughts in life. For example, topics in recent issues: “Training class vs university, the success rate of job hunting”, “how many hospital beds are there in your city” and so on. In order to change the temperature of a technical weekly, I think it is necessary to add some humanistic thinking.

So we decided to add this topic module, which is not limited to the co-editors, but also invites readers to discuss questions with us or throw questions at us. It can be technical thinking, life feelings, reading comprehension, career lessons, career difficulties and so on. In the next issue, we will choose one of the multiple topics to discuss. If the question is beyond our cognitive scope, we will ask other leaders who know us to answer it. So, for this new thing, welcome to contribute interesting topic content ah ~

The development of Tips

Summer

Image compression

In the iOS Package reduction Tip, we learned that resource issues are a major factor affecting package size, and image resources are the most common during development. Using the right image compression tool can effectively reduce the packet.

Lossy compression and lossless compression

Common compression tools include TinyPNG, PngQuant, ImageAlpha, ImageOptim, PngCrush, OpTIPng, PNGOut, PNGNQ, ADVPNG, etc. According to their compression methods, they are divided into two camps: lossy compression and lossless compression.

According to the data, TinyPNG, PNGQuant, ImageAlpha and PNGNQ are lossy compression, basically using quantization algorithm, converting 24-bit PNG images into 8-bit PNG images to reduce the number of colors. Pngcrush, OpTIPng, PNGOut and ADVPNG are lossless compression, using DEFLATE algorithm based on LZ/Huffman to reduce data in IDAT chunk area of image. Generally, the compression rate of lossy compression is much higher than lossless compression.

Compression tools

The following two tools are recommended for background images, placeholders, and large label images that are common in projects

  • TinyPNG4Mac: Using the API provided by Tinify, the current free version of Tinify is compressed to no more than 20 pieces at a time and no larger than 5M. For the average iOS application, enough for daily development use;
  • ImageOptim-CLI: automatically perform the higher compression rate for ImageAlpha lossy compression and ImageOptim lossless compression.

You can compare TinyPng with ImageOptim-CLI by viewing this table.

For small images, such as our common icon icon, we can compress the image by changing its encoding mode to RGB with Palette. You can use ImageOptim to change the encoding of the image to RGB with Palette.

imageoptim -Q --no-imageoptim --imagealpha --number-of-colors 16 --quality 40-80 ./1.png
Copy the code

Learn more about Palette through Palette Images.

By compression, I mean using Xcode’s own compression functionality.

Xcode Negative optimization

We generally use Assets Catalogs to manage the image resources. There will be corresponding optimization methods

During the build process, Xcode reprocesses the image with its own compression algorithm. In the process of building Assest. Car, Xcode will use AcTool to decode the PNG image of Assets Catalogs and obtain Bitmap data. And then use actool’s coding compression algorithm for coding compression processing. So lossless compression without changing the encoding may have little effect on the final package size.

For the same image, Xcode adopts different compression algorithms on different devices and iOS systems, which also leads to different sizes of images on different devices when downloading.

Assest. Car can be analyzed using the Assetutil tool to obtain its specific compression method:

assetutil --info ***.app/Assets.car > ***.json
Copy the code

Note the values of Compression, Encoding, and SizeOnDisk in the Json file.

 {
    "AssetType" : "Image"."BitsPerComponent" : 8."ColorModel" : "RGB"."Colorspace" : "srgb"."Compression" : "deepmap2"."Encoding" : "ARGB"."Name" : "image"."NameIdentifier" : 51357."Opaque" : false."PixelHeight" : 300."PixelWidth" : 705."RenditionName" : "image.png"."Scale" : 1."SHA1Digest" : "294FEE01362591334E3C3B4ECE54AF0EA8491781"."SizeOnDisk" : 113789."Template Mode" : "automatic"
  }
Copy the code

If APP Stochastic can be enabled to generate IPA packages for different devices, and then perform a single decompression for each IPA package, retrieving assets. car to export the corresponding Assets. json, You can also use the Assetutil method mentioned in JD’s APP Slimming practice to export the assets. car file of the specified device from the assets. car file of the general package:

Assetutil -- Idiom phone -- Subtype 570 -- Scale 3 --display-gamut SRGB -- GraphicsClass MTL2,2 -- GraphicsclassFallbacks MTL1,2:GLES2,0 -- Memory 1 --hostedidioms car,watch XXX /Assets. Car -o XXX /thinning_assets. CarCopy the code

Compression of theharm

Don’t blindly pursue the maximum compression ratio, consider both the quality of the compressed image and the actual size of the file after Xcode.

Compressed completed picture as far as possible in the high resolution of the device to see if there will be any problems, let the UI sister take a good look, will not appear noise, burrs and other phenomena.

If an image is lossy and ends up with a large SizeOnDisk in Assets.car, but it works well on all devices, you can try adding it to the bundle and changing the image format to Data. So Xcode doesn’t compress it. But don’t forget to change the calling method to imageWithContentOfFile:.

Parsing the interview

Edit: reverse smoking, shida small sea teng

Interview analysis is a new module, we will explain some high-frequency interview questions according to the topic, this topic is computer network, the following questions are from real interview scenarios.

Enter the url to go to the page and press Enter to refresh the page what happens? URL input to display process?

  1. DNS resolution: When users enter a web address and press enter, the browser gets a domain name, but in the actual communication process, we need to be an IP address, so we need to first convert the domain name into the corresponding IP address;
  2. TCP connection: After obtaining the real IP address of the Web server through DNS, the browser sends a TCP connection request to the Web server. After establishing a connection through TCP three-way handshake, the browser can send the HTTP request data to the Web server.
  3. Sending an HTTP request: The browser sends an HTTP request to the Web server. HTTP is an application layer protocol based on TCP. In essence, it sends a request for a Web page in the ESTABLISHED TCP connection according to the HTTP protocol standard. In this process, operations such as load balancing are involved.
  4. Processing the request and returning: After receiving the HTTP request from the client, the server determines how to obtain the corresponding file according to the content in the HTTP request and sends the file to the browser.
  5. Browser rendering: The browser starts displaying the page based on the response, first parsing the HTML file to build a DOM tree, then parsing the CSS file to build a rendering tree. If the page has a JavaScript script file, then after the JavaScript file is downloaded and loaded, the rendering tree is operated by DOM API and CSSOM API. After the rendering tree is built, the browser starts to lay out the rendering tree and draw it to the screen.
  6. Disconnect: The client and server terminate the TCP connection by waving four times.

What are the stages of congestion control? How to achieve congestion control? TCP congestion control explain?

  1. Congestion control considers the whole network, is the global consideration;
  2. Slow start algorithm: the amount of data to be sent increases gradually from small to large, and the number of packets to be received is doubled every time it is acknowledged. The number increases exponentially and does not increase when it reaches the slow start threshold.
  3. Congestion avoidance algorithm: the maintenance of a congestion window variable, as long as the network is not congested, the test of the congestion window to increase the law of addition, the algorithm can ensure that the network is not congested, send more data;
  4. Fast retransmission: If the serial numbers received by the receiver are discontinuous, the receiver sends three consecutive confirmation packets to the sender.
  5. Quick recovery: The congestion window becomes half of its original size, and the threshold value becomes half of the size when congestion occurs. The congestion avoidance algorithm continues.

How does TCP guarantee reliable transmission? How does TCP implement reliable transmission? Why can TCP guarantee reliable transmission? How to understand TCP connection, reliable and byte stream?

  1. Data block: Application data is divided into data blocks that TCP considers most suitable for sending.
  2. Serial number and confirmation reply: TCP to send each package number, in the process of transmission, every time the receiving party, after receipt of the data to confirm reply to transmission, namely an ACK packet, with corresponding to confirm the serial number of the ACK packet, tell send Fang Chenggong receive what data as well as the next data where to start. In addition, the receiver can sort packets by serial number, send the ordered data to the application layer, and discard duplicate data.
  3. Checksum: TCP keeps the checksum of its head and data parts. This is an end-to-end checksum to detect any changes in the data during transmission. If an error occurs in the verification of a packet segment, TCP discards the packet segment and does not acknowledge the receipt of the packet segment.
  4. Flow control: Both sides of the TCP connection have a fixed buffer space. The amount of data sent by the sender cannot exceed the size of the buffer on the receiver. If the receiver cannot process the data of the sender, the system prompts the sender to reduce the sending rate to prevent packet loss. TCP supports flow control mechanism through sliding window protocol.
  5. Congestion control: Reduces data transmission when a node is congested.
  6. ARQ protocol: It also aims to achieve reliable transmission. Its basic principle is to stop sending each packet and wait for the confirmation of the other party. Send the next packet after receiving confirmation;
  7. Timeout retransmission: When TCP sends a packet segment, it starts a timer and waits for the destination to acknowledge receipt of the packet segment. If no acknowledgement is received within a certain period of time, the packet segment is resend.

Good blog

King Pilaf is here. I am Xiong Da

The topic of this issue: Startup optimization

How to optimize cold startup for iOS apps — From FiTeen

To do a good job, he must sharpen his tools. To optimize startup speed, start by understanding what a cold start is and what phases it goes through, and then identify key points to optimize. The author introduces the theoretical knowledge and detection tools of startup in detail, including the difference between cold startup and hot startup, how to check the time of the stage and the interpretation of related concepts. This is the necessary homework to optimize the start speed, for want to do start speed optimization related students, it is worth learning.

2. Deep dive into iOS startup speed optimization (binary rearrangement) — from nuggets: SimonYe

The binary rearrangement principle is that during the startup process, various functions are called, which are distributed in various TEXT segments and may not be contiguous. In this case, multiple Page faults are required to create pages. Each page fault is approximately 16KB. If we rearrange the binaries and put them together to reduce the number of page faults, wouldn’t that reduce the time taken? The author introduces the theoretical basis of binary rearrangement, and the practical process, as well as the summary of binary rearrangement, the specific binary rearrangement can improve, it is up to you to practice. If you want to practice binary rearrangement, this article will help you.

🐻 record the process of 30% startup speed optimization — from nuggets: I am Xiong Da

Earlier pods only supported dynamic library imports for Swift projects, but a new feature use_frameworks was added in Cocoapods 1.9. :linkage => :static Supports static library import, if you are a Swift project, you can try this. This article also introduces the difference between dynamic and static libraries.

Iv. Douyin Quality Construction — iOS startup optimization principle — From Nuggets: Bytedance technical team

Interviewers often ask what happens from when the user clicks on the icon to when the user sees the first frame of the image. This article will give a very comprehensive answer. The first step in doing startup optimization is to understand what iOS does at startup. This paper first introduces some basic concepts, such as startup type, DYLD, MMAP, Page In, etc. The IPA construction process was then introduced, revealing how to implement useless code detection based on LLVM pegs. This paper mainly introduces the startup process of DYLD3. What does DyLD3 cache? What does Rebase and Bind do? Where should I start? These are common interview questions.

5. 58.com App performance Governance Practice -iOS startup time optimization — from the official account: 58 Technology

This article is 58.com APP startup optimization practice collation. From startup time monitoring to startup governance articles are introduced. This paper introduces some schemes such as how to compare the startup time of two apps horizontally, how to realize startup optimization through dynamic library lazy loading, and how to collect Swift symbols. It has certain reference significance to the practice of APP startup optimization.

6. Optimization of the first screen opening of The Hello Travel iOS App in seconds — from the official account: Hello Technology

This article overlaps slightly with the previous two articles, but focuses on the impact of picture and animation decoding on APP startup. This article provides several useful examples, such as the performance problems of the Lottie framework when handling transcoding synchronously. The author proposes the problem that Lottie can block the main thread of large picture or multi-picture key frame, and gives the corresponding processing method.

Learning materials

Mimosa

RSSHub

Address: docs. Rsshub. App /

RSSHub is an open source, easy to use, easily extensible RSS generator that can generate RSS feeds for any kind of weird content. RSSHub is developing rapidly with the help of the open source community. It has been adapted to hundreds of websites with thousands of content, and can be used with browser extensions and mobile apps. You are also welcome to write your interested subscription feeds.

Writing specification of Chinese technical documents

Address: github.com/ruanyf/docu…

Writing specifications for Chinese technical documents from Ruan Yifeng. When editors read technical articles on major blog platforms, they are often troubled by the format of the article, and even close the article directly in serious cases. In fact, the writing standards of Chinese copywriting are not so complicated. After learning ten minutes and practicing a few articles, you can write a decent copywriting format. Good writing standards can not only save the cost of communication, but also improve the temperament of the article. Learning is to earn, is a lifetime wealth. Also strongly recommend this Chinese copy layout refers to north for reference.

Tools recommended

zhangferry

WWDC

Address: WWDC. IO /

Software status: Free, open source

introduce

An open source, unofficial WWDC video app that supports video downloads, up to 5 minutes of video cutting, bookmarking, iCloud syncing, Chromecast casting, picture in picture, and more. It has only a few more features than the official app (the new version of the official Developer app added snippet preview), and has been updated fairly quickly, with version v7.3.3, which allows you to view Sessions from 2021.

ScreenSize

Address: www.screensizes.app/

introduce

An online sizing site for Apple devices and their components, very complete. Here is a brief summary of its contents in iPhone devices:

  • Security zone size in horizontal and vertical mode
  • Size of the three Widget sizes
  • Size of standard mode and system amplification mode
  • A comparison of the dimensions of each device

Phase to recommend

IOS Fishing Weekly eleventh issue

IOS Fishing Weekly issue 12

IOS Fishing Weekly issue 13

IOS Fishing Weekly 14th issue

IOS Fishing Weekly 15th issue