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

  1. Load dylibs
  • Avoid embedding (embedded)dylib, load inlinedylibHigh performance overhead
  • Merge existingdylibAnd using static libraries (static archives), and reducedylibThe number of uses of
  • Lazy loadingdylibBut be carefuldlopen()It can cause some problems, and lazy loading actually does more work
  1. 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 (clasS), method (selector), classification (categoryThe number of)
  • To reduceC++Number of virtual functions (creating a virtual function table is expensive)
  • useswiftStructs(Internal optimization, fewer symbols)
  1. Objc setUp
  2. Initializers
  • Less in class+loadDo 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 reduceC++The number of static global variables

1.3.2 the main stage

  1. Comb through all binary/tripartite libraries and find libraries that can be lazily loaded for lazy loading, such as the home controller ortabBarThe controller’sviewDidAppearMethod, and ensure that it is executed only once (according to the project structure, in the appropriate place)
  2. 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.
  3. Avoid complex/redundant calculations.
  4. Avoid the first interface the user sees (home controller or sign-in page)viewDidLoadviewWillAppearToo 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
  5. 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

  1. Path:PathIs the path to generate the executable.
  2. Arch:ArchRefers to schema types.
  3. Object files:Object FilesIt lists all of the executable filesobjAs well astbd. Each line represents the number of the file.
  4. Sections: eachSectionContains theAddress,Size,SegmentAs well asSection.Mach-OThe virtual addresses in the file are eventually mapped to physical addresses, which are divided into different segment types:TEXT,DATAAs well asLINKEDITAnd 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. It is read and write, but not executable. LINKEDIT contains loader metadata, such as function names and addresses, and is read-only. The Segment is then divided into different sections. Each Section stores different information. For example, objc _ methName is the name of the method.

  • Address: indicates the start IP 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.
  1. Dead Stripped Symbols

1.5 Specific optimization time acquisition? Have you seen how much optimization is actually online?

  1. Pre-main phase measurement:DYLD_PRINT_STATISTICS
  2. Main () phase measurement: in the firstmain()We use variables in functionsStartTime didFinishLaunchingWithOptionsGet the current time again

2. VC lifecycle

  1. +load: program starts after the systemmainBefore the function is called, the system will load allloadMethod to configure some resource packs in advance orhook, (can interrupt to see the result, I personally tested)
  2. +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
  3. +alloc: called when the system allocates memory for the current class, in CmallocThis step
  4. -initWithCoderThrough:storyBoardVc, which needs to be deserialized, will be called
  5. -initWithNibName:bundleThrough:xibA file orinitVc method instantiation, this method will be called, in factinitMethods will always follow that method
  6. -initVc will call through pure code instantiation, and it will eventually callinitWithNibName:bundle:methods
  7. -loadViewAfter the Vc is instantiated, you can load some of the system’s general views
  8. -viewDidLoad: Usually loads a custom view or initializes a property, which is called after the view is loaded
  9. -viewWillAppear: View is about to appear
  10. -viewWillDisappear: View is about to disappear will be called
  11. -viewWillLayoutSubviews: The view is about to be laid out after loading
  12. -viewDidLayoutSubviewsThe layout is complete after the view is loaded
  13. -didReceiveMemoryWarningWhen the view is loaded, a memory warning is displayed
  14. -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.

There is no end to learning.