1. Binary rearrangement,
1.1 How to do clang Piling
1.2 can clang pile be obtained by c++ method?
C functions, OC methods, block, swift methods are not available but can be “hooks” at compile time using -finstrut-functions, or static scanning schemes that are not perfect but cost the least.
1.3 Besides binary rearrangement, what are the other methods to start optimization
1.3.1 Pre-Main Phase
- Load dylibs
- Avoid embedding (
embedded
)dylib
, load inlinedylib
High performance overhead - Merge existing
dylib
And using static libraries (static archives
), and reducedylib
The number of uses of - Lazy loading
dylib
But be carefuldlopen()
It can cause some problems, and lazy loading actually does more work
- Rebase/Bind
In the process of loading dylib, the system introduced ASLR (Address Space Layout Randomization) technology and code signature for safety. Due to ASLR, images (including executables, dylib, and bundle) are loaded at random addresses, and there is a slide deviation from the preferred_address, which dyLD needs to fix to point to the correct address.
- Reduce ObjC classes (
clas
S), method (selector
), classification (category
The number of) - To reduce
C++
Number of virtual functions (creating a virtual function table is expensive) - use
swiftStructs
(Internal optimization, fewer symbols)
Objc setUp
Initializers
- Less in class
+load
Do things in the method and put them off as long as possible+initiailize
- Reduce the number of constructor functions and do fewer things in constructor functions
- To reduce
C++
The number of static global variables
1.3.2 the main stage
- Comb through all binary/tripartite libraries and find libraries that can be lazily loaded for lazy loading, such as the home controller or
tabBar
The controller’sviewDidAppear
Method, and ensure that it is executed only once (according to the project structure, in the appropriate place) - Sort out the business logic and delay the execution of the logic that can be delayed. Check for new versions, register for push notifications, and so on.
- Avoid complex/redundant calculations.
- Avoid the first interface the user sees (home controller or sign-in page)
viewDidLoad
和viewWillAppear
Too much to do, the first page will not be displayed until these two methods have been executed, and some views that can be created lazily should be lazy/lazy loaded - The home controller or registration login page is built in pure code
1.4 Link Map Data Structure
A Link Map File is a Link information File generated when Xcode generates an executable File. It describes the construction part of the executable File, including the distribution of code segments and data segments
1.4.1 Composition of linkMapfile
- Path:
Path
Is the path to generate the executable. - Arch:
Arch
Refers to schema types. - Object files:
Object Files
It lists all of the executable filesobj
As well astbd
. Each line represents the number of the file. - Sections: each
Section
Contains theAddress
,Size
,Segment
As well asSection
.Mach-O
The virtual addresses in the file are eventually mapped to physical addresses, which are divided into different segment types:TEXT
,DATA
As well asLINKEDIT
And so on. The meanings of each paragraph are as follows:
TEXT contains the code to be executed. This code is read-only and executable. DATA contains DATA that will be changed, such as global variables, static variables, etc., and is readable and writable, but not executable. LINKEDIT contains the loader’s metadata, such as function names and addresses, and is read-only. The Segment is divided into sections that store different information. For example, objC _ methName is the name of the method
- Symbols: Symbols contain the following information:
-
Address: start Address \
-
Size: indicates the occupied memory Size in hexadecimal notation.
-
File: Indicates the number of the File in which the Name resides, which is the number in parentheses in the Object Files section.
Dead Stripped Symbols
1.5 Specific optimization time acquisition? Have you seen how much optimization is actually online?
- Pre-main phase measurement:
DYLD_PRINT_STATISTICS
- Main () phase measurement: in the first
main()
We use variables in functionsStartTime didFinishLaunchingWithOptions
Get the current time again
2. VC lifecycle
+initialize
: The current class or its subclass is called for the first time when it is not initialized. If the current class or its subclass is not called again when it is initialized several times, it usually does some work for initialization in advance+alloc
: called when the system allocates memory for the current class, in Cmalloc
This step-initWithCoder
Through:storyBoard
Vc, which needs to be deserialized, will be called-initWithNibName:bundle
Through:xib
A file orinit
Vc method instantiation, this method will be called, in factinit
Methods will always follow that method-init
Vc will call through pure code instantiation, and it will eventually callinitWithNibName:bundle:
methods-loadView
After the Vc is instantiated, you can load some of the system’s general views-viewDidLoad
: Usually loads a custom view or initializes a property, which is called after the view is loaded-viewWillAppear
: View is about to appear-viewWillDisappear
: View is about to disappear will be called-viewWillLayoutSubviews
: The view is about to be laid out after loading-viewDidLayoutSubviews
The layout is complete after the view is loaded-didReceiveMemoryWarning
When the view is loaded, a memory warning is displayed-dealloc
: the instantiation is destroyed and memory reclamation is called
3. copy / mutableCopy
Mutable object replication:
Both are deep copies, but the object returned by copy is immutable.
For containers, the element object is always a pointer copy. If you want element objects to be object copies, you need to implement deep copies.
4. NSUserDefault Storage location
~/Library/Preferences, plist file storage
5. How does Https ensure data security
SSL+HTTP is a network protocol for encrypted transmission and identity authentication
Whether the public and private keys are encrypted after encryption
Symmetric encryption + asymmetric encryption, we can use asymmetric encryption to transmit the key in the symmetric encryption process, and then we can use symmetric encryption to transmit data
6. git reset
You can make HEAD point somewhere else and it has three modes: soft, mixed, and hard
6.1 reset soft
Reset — Soft resets HEAD and branch, preserves the contents of the working directory and the staging area, and puts the new differences in the staging area.
6.2 reset mixed
Reset with no arguments (mixed) : Keeps the working directory and clears the temporary area reset with no arguments –mixed is used by default. Its behavior is to keep the working directory and clear the staging area. That is, changes to the working directory, the contents of the staging area, and any new file differences caused by reset are put into the working directory. In short, “Mix all differences in the working directory.”
6.3 reset hard
Reset — Hard resets the stage and working directories at the same time as HEAD and branch. When you add –hard to reset, the contents of your stage area and working directory will be reset exactly to the new location of HEAD. In other words, your non-commit changes will be erased.
Authors: Xu Xiaosan, Zhu Purui, Little Puppet