This profile

  • What is dark time?
  • Tips include a summary of Fastlane usage, the difference between Minimumline acing and minimumInteritemSpacing, and a process for locating RN fever issues.
  • This topic describes the variable capture mechanism of block.
  • The excellent blog has brought several compilation optimization articles.
  • The learning materials come with a video tutorial on designing a computer from scratch, as well as text tutorials on Git and regular expressions.
  • Development Tools introduces two related tools for code fragment collation.

This topic

@Zhangferry: I’m reading a book called Dark Time. I think I don’t know what the title of this book is because the author invented this word.

Reading books and remembering things in books is only memory, not reasoning. Only by reasoning can you deeply understand a thing and see what others can’t see. This part of reasoning process is your thinking time, which is also the “dark time” that occupies a significant proportion in your life. You walk, you buy groceries, you wash your face and hands, you ride the bus, you go shopping, you travel, you eat, you sleep — all these time can be called dark time. You can make the most of it by thinking, ruminating and digesting what you normally read and read. These hours may seem small, but over time they can have a huge effect.

Dark time is thought time, because thought is the human “background thread,” which we don’t usually notice, but which is very real and very important. But thinking time is a little narrower, because most of the time we don’t think all the time. I have tried to expand Liu Weipeng’s concept of dark time to include the fragmentary but unused time in addition to thinking time. “Bright time”, dark time if can use, it is excellent.

So far I have two practices with dark time applications:

1. Walking to and from work is time to think. I now use a different route to make my commute longer, taking about 15 minutes each. During this time, I will try to think about today’s work content and plan daily tasks. Or recall an article you read recently, play it out in your mind and try to retell it; Or just look at people walking by and imagine what I would see myself from another point of view if I were them. In short, get your brain working.

The process of waiting is the movement time. When waiting for someone or at the traffic light, I will try to make myself exercise, such as small movements like footpads, bigger movements like jumping, running. Exercise is an anti-human thing, so it can not be planned, a planning to fight against laziness, so simply at any time free to move two. Often this small exercise experience, if suddenly interrupted by the need to get to work, can leave a sense of unfinished business.

Of course there are other things that can be done, but it’s important that we understand and feel this dark time thing, and then figure out how to use it. At least some of my attempts have made some otherwise boring hours a little more interesting.

The development of Tips

2. This is the best way to write a book

Summary of Fastlane usage

Image credit: IOS-Tips

React Native 0.59.9

Content contribution: YYhinBeijing

The phenomenon of the problem is: If the RN page is placed for a long time or different RN pages are operated repeatedly, the mobile phone will become very hot and will not automatically cool down. The temperature will be cooled only when the process is killed. The version is 0.59.9, and almost different mobile phones and different system versions of mobile phones have encountered this problem. Here’s how to locate the problem using code comments, followed by CPU usage:

1. Native: 7.2%

2. No network without Flatlist: 7.2%

3, Network + FlatList: 100%+

4, network + no FlatList: 100%+

5. Remove loading: 2.6%-30%, and the loading will be reduced

6, network and FlatList all open, only close loading minimum 7.2%, can reduce, maximum 63%

First, the network is causing high CPU usage. Then the network comments out RNLoading (our own loading animation) and the memory usage is not high. Loading loading loading loading loading loading loading loading loading loading loading loading loading loading loading loading loading loading loading Although it is not a special problem, the process of finding, locating and solving the problem is still instructive, that is, to determine the scope and then constantly narrow the scope.

Parsing the interview

Edit: reverse smoking, Small sea teng

Interview analysis will explain some high-frequency interview questions according to the theme. This interview question is the variable capture mechanism of block.

Block variable capture mechanism

The variable capture mechanism of the block is to ensure that the internal block can normally access the external variables.

1. For global variables, they are not captured inside the block and are accessed directly. Because of scope, global variables can be accessed directly anywhere, so they are not captured.

2. For local variables, they cannot be accessed directly from outside, so they need to be captured.

  • For local variables of type auto (all variables defined by us are of type Auto by default, but omitted), a member variable of the same type is automatically generated inside the block to store the value of the variableValue passed.A local variable of type Auto may be destroyed, its memory will disappear, and the block will not be able to access that memory when executing code in the future, so it will capture its value. Since this is value passing, we can change the value of the variable captured outside the block without affecting the value of the variable captured inside the block.
  • A local variable of type static. A member variable of the same type is automatically generated inside the block. It is used to store the address of the variablePointer passed. Static variables are always stored in memory, so just capture their address. Conversely, since we are passing Pointers, modifying the value of the captured variable outside the block affects the value of the captured variable inside the block.
  • For local variables of object type, a block is captured along with its ownership modifier.
    • If the block is on the stack, there will be no strong reference to the object
    • If the block is copied to the heap, the inside of the block will be calledcopy(__funcName_block_copy_num)Function, which is called inside copyassign(_Block_object_assign)Function, assign will operate on the variable’s ownership modifier to form a strong or weak reference.
    • If a block is removed from the heap, that is, when it’s released, it’s called inside the blockdispose(_Block_object_dispose)Function, dispose function will automatically release the referenced variable.
  • for__block(which can be used to solve the problem of not being able to modify the value of the auto variable inside a block)__blockThe variable is wrapped as a__Block_byref_varName_numObject. Its memory management is almost equivalent to accessing the auto variable of the object type, but there are differences.
    • If the block is on the stack, it will not be right__blockVariables generate strong references
    • If a block is copied to the heap, the copy inside the block is called

    The copy function, the copy function will call the assign function internally, and the assign function will be directly connected to the__blockVariables form a strong reference (retain).

    • If a block is removed from the heap, the dispose function inside the block is called and the reference is automatically removed__blockVariable (release).

  • be__block Memory management for modified object types:
    • If the __block variable is on the stack, there will be no strong reference to the pointing object

    • If the __block variable is copied to the heap, the copy(__Block_byref_id_object_copy) function inside the __block variable is called, and the copy function inside the __block variable is assigned, The assign function, in turn, operates on the variable’s ownership modifier to form a strong or weak reference. (Note: only retain under ARC, not MRC, so it is possible to use __block to solve the circular reference problem under MRC.)

    • If a __block variable is removed from the heap, the Dispose function inside the __block variable is called, which automatically releases the pointed object.

By understanding the variable capture mechanism of blocks, we can better deal with memory management and avoid memory leaks caused by improper use.

A common block loop reference is self(obj) -> block -> self(obj). The reason the block strongly references self here is that for local variables of object type, the block is captured along with its ownership modifier, and the default ownership modifier for an object is __strong.

self.block = ^{
    NSLog(@ "% @".self);
};
Copy the code

Why does it say self is a local variable? Because self is an implicit argument to the OC method.

To avoid circular references, we can use __weak, where the block will no longer hold self.

__weak typeof(self) weakSelf = self;
self.block = ^{
    NSLog(@ "% @", weakSelf);
};
Copy the code

To avoid early release of self during a block call, we can use __strong to hold self during block execution, which is known as weak-strong-dance.

__weak typeof(self) weakSelf = self;
self.block = ^{
    __strong typeof(self) strongSelf = weakSelf;
    NSLog(@ "% @", strongSelf);
};
Copy the code

Of course, we usually use more than @Weakify (self) and @Strongify (self).

@weakify(self);
self.block = ^{
    @strongify(self);
    NSLog(@ "% @".self);
};
Copy the code

If you use RAC’s weak-strong-dance, you can also do this:

@weakify(self, obj1, obj2);
self.block = ^{
    @strongify(self, obj1, obj2);
    NSLog(@ "% @".self);
};
Copy the code

If the block is nested:

@weakify(self);
self.block = ^{
    @strongify(self);
    self.block2 = ^{
        @strongify(self);
        NSLog(@ "% @".self); }};Copy the code

Do you wonder why @Weakify (self) is no longer needed internally? This problem is left to you to think and solve!

Rather than simply circular references to each other, large ring references created by blocks require more care and insight, such as:

TYAlertView *alertView = [TYAlertView alertViewWithTitle:@"TYAlertView" message:@"This is a message, the alert view containt text and textfiled. "];
[alertView addAction:[TYAlertAction actionWithTitle:@ "cancel" style:TYAlertActionStyleCancle handler:^(TYAlertAction *action) {
    NSLog(@ % @ - % @ "".self, alertView); }]].self.alertController = [TYAlertController alertControllerWithAlertView:alertView preferredStyle:TYAlertControllerStyleAlert];
[self presentViewController:alertController animated:YES completion:nil];
Copy the code

There are two circular references here:

  1. self -> alertController -> alertView -> handlerBlock -> self
  2. alertView -> handlerBlock -> alertView

Avoid circular references:

TYAlertView *alertView = [TYAlertView alertViewWithTitle:@"TYAlertView" message:@"This is a message, the alert view containt text and textfiled. "];
@weakify(self, alertView);
[alertView addAction:[TYAlertAction actionWithTitle:@ "cancel" style:TYAlertActionStyleCancle handler:^(TYAlertAction *action) {
    @strongify(self, alertView);
    NSLog(@ % @ - % @ "".self, alertView); }]].self.alertController = [TYAlertController alertControllerWithAlertView:alertView preferredStyle:TYAlertControllerStyleAlert];
[self presentViewController:alertController animated:YES completion:nil];
Copy the code

Use block implicitly retains self; use block implicitly retains self; use block implicitly retains self; Explicitmention ‘self’ to indicate this is intended behavior.

The reason is that using _variable directly in a block results in an implicit strong reference to self in the block. Xcode believes that this may implicitly lead to circular references, which may cause trouble for developers, and it is really difficult to check if you don’t look carefully. I have been looking for this circular reference for a long time, and I even invited my tutor to find out the reason. So the warning is to explicitly use self in a block so that the block explicitly retains self. Use self->_variable or self.variable.

If you use @Weakify and @Strongify it really doesn’t cause circular references because @Strongify declares the variable name as self. So if you use weak Typeof (self) weak_self = self; How about strong typeof(weak_self) strong_self = weak_self?

Good blog

King Pilaf is here. I am Big Bear

This topic: Compilation optimization

1. Principles and applications of iOS compilation process — from CSDN: Wenchen Huang

Before doing compilation optimization, first understand the principles of compilation! From the perspective of iOS, the author introduces the compilation principle in vernacular, which is easy to understand.

2, Xcode compile as fast as the wind series – analysis compilation time – from teng community: side dishes and old birds

Before you can optimize build speed, a proper analysis tool is necessary. It can tell you which parts of the build are taking longer to identify problems and solve them. This article describes several ways to analyze build times to help you analyze build times. The author has a companion book that I recommend you to read.

3, iOS wechat compilation speed optimization sharing — from the Cloud + community: wechat terminal development team

This paper introduces the compilation optimization from the shallow to the deep. Firstly, the author introduces the common existing solutions, and makes some optimization by using the existing solutions as well as simplifying the code, changing the template base class to virtual base class, and using PCH. The wonderful part of this paper is that the author did not stop there, but started from the compilation principle, combined with quantitative means, to analyze the bottleneck of compilation time. After finding the bottleneck of the problem, the author tried to optimize manually, but the efficiency was low. In the end, IWYU added ObjC support to efficiently handle some of the redundant header files.

How does iOS compile speed increase steadily by more than 10 times

The process of iOS compilation and efficiency improvement. The author makes an analysis of common optimizations and lists their advantages and disadvantages. Those who want to do compiler optimization can refer to this article. For mainstream technical solutions in the industry, other technical articles often only introduce the advantages, the disadvantages of the solution is not thorough. This article expounds the advantages and disadvantages of common schemes from the perspective of practitioners, which is of great reference value. The article introduces dual private source binary components and compares them to CCache, and finally lists the function points supported by the solution.

How does iOS compile speed increase steadily by more than 10 times by two

As a companion article to the above, this article details the scheme details of dual private source binary components and how to use them. Those who are interested in this scheme can pay attention.

6. A tool that can improve the compiling speed of large iOS projects by 50% — from meituan technical team: Si Qi Xu Tao Shuangye

This paper mainly introduces how to optimize the header file search mechanism to achieve the compilation speed, the full source compilation efficiency increased by 45%. This article covers a lot of knowledge, such as the role of THE HMAP file and the roles of Public, Private and Project in Build Saturnis-headers. This article examines in detail the logic that podSpec creates Header artifacts and the reason why the Use Header Map fails. There’s a lot of dry stuff, so I might have to read it a few more times.

Learning materials

By Mimosa

Design a computer from zero to one

Address: www.bilibili.com/video/BV1wi…

From Ele LABS, the main purpose of this series of videos is to give you an intuitive understanding of how computers work, as an introduction to further study of computer science. It is best to have some basic knowledge of digital and analog circuits. Ele Lab also has some basic knowledge of digital and analog circuits for your reference.

Git Cheat Sheet

Address: github.com/flyhigher13…

Git Cheat Sheets prevent you from having to remember all your Git commands! Novice friendly, can be used to refer to simple git commands.

A 30-minute introduction to regular expressions

Address: deerchao. Cn/tutorials/r…

In 30 minutes you will understand what regular expressions are and have some basic understanding of them. Don’t be intimidated by the complexity of these expressions. Just follow my steps and you’ll see that regular expressions aren’t as difficult as you might think. In addition to being an introductory tutorial, this article is intended to be a reference manual for regular expression syntax that you can use in your daily work.

Tools recommended

2. This is the best way to write a book

SnippetsLab

Address: www.renfei.org/snippets-la…

Software status: $9.99

Software Introduction:

A powerful snippet management tool, no longer copy and paste, SnippetsLab is designed to be more interactive with Apple, enabling quick navigation. Additionally, Github Gist content can be synced and backed up using iCloud.

CodeExpander

Address: codeexpander.com/

Software status: Regular free, premium paid

Software Introduction:

A set input enhancement, snippet management tool for developers, cross-platform support, and cloud synchronization (Github/ code cloud). The free version contains around 90% of the functionality and is more widely used than SnippetsLab, including even some snippet processing of everyday text.

About us

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

Content of the past

IOS Fish Weekly issue 17

IOS Fish Weekly issue 16

IOS Fish Weekly issue 15

IOS Fish Weekly, issue 14