This profile

  • Topic: Chrom 100 has been released, and the guidelines for approving apps for readers have been updated
  • Interview module: StripeMap template class in Runtime
  • Excellent blog: New features and features in Swift 5.6 and Xcode 13.3
  • Real-time Design is a professional UI design tool that can collaborate in real time online
  • Development tools: Decode, willXcode Interface BuilderFile (XibStoryboardFile) toSwiftThe source code.

information

Google Chrome was released to version 100

The new version update is not big, will continue to significantly reduce memory, CPU usage, speed will be faster. The app icon has also been changed, with smaller red, yellow and green edges. In terms of the development of ICONS, Google’s design style is becoming more and more flat.

Updates distributed by the reader App

Last year, Apple announced an update to the App Store in early 2022 that will allow “Reader” App developers to provide a link to their website within the App for users to create or manage accounts. Starting today, guideline 3.1.3(a) in the App Store Review Guide will be updated to clarify that reader App developers can now apply for account authorization for external links.

Parsing the interview

Hello World

StripeMap<T>Template class

StripeMap

is a class defined in OC Runtime for reference count tables, Synchroinzed, lock lists for property Settings, and more. This class can be thought of as a special kind of HashMap.

The particularity is that a normal HashMap key&value is one-to-one, and even if there are hash conflicts, they are resolved by other methods, but StripeMap is many-to-one for key&Value.

Why did Apple design a StripeMap table structure for memory management? Let’s take a look at the simplified definition:

enum { CacheLineSize = 64 };

template<typename T>
class StripedMap {
#ifTARGET_OS_IPHONE && ! TARGET_OS_SIMULATOR
    enum { StripeCount = 8 };
#else
    enum { StripeCount = 64 };
#endif
    struct PaddedT {
        T value alignas(CacheLineSize); / / alignment
    };

    PaddedT array[StripeCount];
};
Copy the code

StripeMap exists to optimize performance bottlenecks caused by high frequency access to

, especially in multi-threaded resource contention scenarios. According to the notes, it is mainly reflected in the following aspects

  • The object structure maintains an array that is divided into different pages for different devices, 8 for mobile devices and 64 for others.
  • It uses the address of the object as the key, hashes an index, and retrieves the corresponding index<T>The value. The mapping relation isvoid* -> <T>
  • Do memory alignment to improve CPU cache hit ratio

Separation lock optimization

StripeMap is essentially the implementation of the concept of separate locks, a brief overview of personal understanding of separate locks

We all know that in multi-threaded scenarios, if multiple variables can be accessed and modified by multiple threads, the best way is to use different lock objects for different variables to achieve resource management. This prevents multiple threads from blocking while accessing one variable while accessing other unrelated variables. This is actually an application of split locks. That is, to avoid waiting for access to the same lock.

Separate lock is a further optimization of the above ideas, for the same frequently-accessed object, segmented management can solve the resource competition between threads. Take SideTables as an example:

Split the SideTables table structure into eight pieces, each maintaining a lock object. This allows access to up to 8 page table data while maintaining thread safety during high frequency access. The idea is array + hash function (address pointer to index index).

typedef unsigned long uintptr_t;

static unsigned int indexForPointer(const void *p) {
     uintptr_t addr = reinterpret_cast<uintptr_t>(p);
     return ((addr >> 4) ^ (addr >> 9)) % StripeCount;
}
Copy the code

Cast address pointer to uintptr_t unsigned long integer, uintptr_t defined as 8 bytes, ensuring that the full conversion of pointer (8 bytes) will not overflow. Then, bitwise operations and modulo are performed to ensure that the index falls within the StripeCount index range.

CPU Cache Line

As mentioned in the third optimization above, memory alignment is done using CacheLineSize when defining template type

. In general, the purpose of memory alignment is to speed up CPU access, and this is no exception,

But it is curious that the common size of memory alignment in OC is the 16-byte alignment of objects. The StripedMap defines what 64-byte alignment is for.

Here’s the straight conclusion (skip the theory part if you’re not interested) : The Cache line is the size of the data exchanged between the CPU Cache and main memory at one time. It varies by CPU. On Mac and iOS, the Cache line is 64 bytes.

Out of exploratory spirit, I did a search for keywords. Since I don’t know much about operating systems, THIS is just an overview:

  1. The CPU Cache Line is the smallest unit of data transmission and operation between CPU caches. This means that each exchange between caches is a multiple of the Cache Line. That’s the precondition.

  2. Another important point is that L1 and L2 caches are not shared between different cores. Threads in other cores need to send RFO messages to access data in the current core Cache. The current core resets the hit Cache Line state and writes data to L1 / L2 => L3/ main memory. The other core reads again before it can be accessed. If frequently accessed in two core threads. There will be performance loss.

We assume a scenario where two unrelated variables var1 and var2 are less than 64 bytes and are close to each other in memory. A core loads the Cache Line containing the memory region var1 and var2 and updates the value of var1. The second situation above occurs when you are in another core and need to access VAR2.

The solution to this problem is space for time. That’s what StripedMap does. Memory alignment to ensure that the SideTable structures of different pages are on different Cahce lines. This allows different core threads to process two variable values simultaneously.

  • Objective-c Runtime StripedMap
  • CPU caching principles and applications

Good blog

This installment will be a compilation of blog posts about the new features and functionality of the recently released Swift 5.6 and Xcode 13.3.

Finishing editor: Dongpo elbow son

1. New Swift 5.6 features — from nuggets: YungFan

Swift 5.6 introduces a number of new features to the language, while improving some other features to help developers make a smooth transition to Swift 6. This article introduces the new features of Swift 5.6. In addition, after each Swift upgrade, HackingWithSwift.com will have a special article to introduce the new content, interested friends can continue to follow.

2. Swift 5.6 SE-0335 Introduction To An understanding of Such an obstacle — From the Excavation of Gold: The Jackal of Red Ridge Mountain

@Dongpo Elbows: In Swift 5.6’s new feature, a new keyword, Any, is introduced to flag The Interface Type. This change has the potential to break existing code in the future, causing compatibility issues in Swift 6. All Swift developers should keep abreast of it. The author of this article will introduce and discuss the use of any and the reason for its existence.

Publish DocC documents as static sites on GitHub — from Moritz Philip Recke

Swift 5.6 implements functions such as an extensible build tool (SE-0303) and extension command plug-in (SE-0332) for Swift Package Manager. This tutorial shows you how to take advantage of the new functionality to generate DocC documents and process them as statically managed documents.

Xcode 13.3 adds the ability to use SPM binary dependencies in private repositories — from Marco Eidinger

@Dongpoeouzi: Not being able to pass binary distribution libraries is one of the major factors preventing developers from fully switching to Swift Package Manager. The XCFramework was added to Xcode 12 to make binary distribution possible. Xcode 13.3 continues with the XCFramework’s support for private repositories. Developers further protect their intellectual property by making their code available as binaries when developing private closed source libraries.

5, Swift asynchronous algorithm introduction — from: Tony Parker

Swift 5.5 brings a new asynchronous development experience to Swift. Apple has unveiled Swift Async Algorithms, a cross-platform open source project that gives developers the ability to process asynchronous sequences more naturally and efficiently. This library requires Swift 5.6 support.

stories

Something interesting to read/browse this week.

1. Pan Aimin: Evolution of computer programs — 30 Years of my Programming life — from CSDN

@Zhangferry: This article is the self-narration of Pan Aimin. The thirty years of computer life also correspond to the thirty years of the development of computer industry. From the code running mode, network, artificial intelligence, interactive form of these dimensions of the development of some summarized, the end of the paper on the future of program technology to do a wave of prediction.

One mentioned the noun, digital twin, “this is a concept of Internet of things refers to the information platform in the simulated physical entity, processes or systems, similar entity system in the information platform of twins. With the aid of digital map, can understand the state of the physical entity on information platform, can even to control physical entity predefined interface components inside.” It corresponds to people’s imagination of the future, and the development of this scene is still in the exploratory period.

** I have always believed that writing code by programmers is a creative activity, which is the sanctity of the programmer profession. ** and it comes from a “senior programmer” who has been working in the computer industry for 30 years. Once upon a time, I also have this idea, but after several years of work and the environment constantly someone to recognize the reality of the call, I feel that they have been infected that abandoning the ideal to talk about reality is a mature, self-think recognize the reality, is it the opposite?

2. The 30-year program life of Pan Aimin, the first generation programmer in China — from the public account: CSDN

@Zhangferry: Recently I have been reading the way of Programmer Training – Linking, Loading and Library, which was co-written by Pan Aimin, so I have found several articles about him. This article is also a self-report, mainly talking about his career experience, from Microsoft Research Asia, Shanda Innovation Institute, Alibaba and entrepreneurship hangzhou Command set. What I am interested in is pan Aimin’s experience of participating in YunOS at Alibaba (2013), which happened to be in the Asian Research Institute.

Starting from the Windows performance diagnosis analysis, I studied the internal mechanism of Windows, analyzed the most core modules of Windows, such as thread scheduling, memory management and I/O, and formed a set of systematic diagnosis methods. With these foundations, I further consider the performance of the application layer, take the browser rendering engine as the research object, analyze the entire calculation process of the rendering engine, and mine the space that can be optimized. The idea is to keep the response process efficient by removing as many repetitions as possible from the calculation process. These research work laid a solid foundation for me to do operating system later.

After that, I designed a new mobile operating system VisionOS in Shanda Innovation Institute. Although VisionOS failed, I also accumulated a lot of experience, so that when I worked as YunOS in Ali, “I wanted to make cloud OS”. In the end, YunOS did not succeed, the result is not without emotion. But looking back at Pan aimin’s life, one of the key points is the experience of studying Windows in the Asian Research Institute, which provides a solid foundation for all his subsequent work.

3. Variflight Real-time tracking radar for global flights

Zhangferry: This website can view the real-time flight data of all flights around the world, and it is updated every few seconds, so how do you get the data? Notice that there is an acronym at the top of the site: ADS-B. It stands for Automatic Dependent Surveillance — Broadcast.

It is an aircraft surveillance technology in which an aircraft determines its location using a satellite navigation system and broadcasts regularly so it can be tracked. The broadcast does not need to be manually operated, but is triggered automatically and regularly as a basic function, and a new generation of aircraft will be required to have it. It contains two services, ADS-B Out, for broadcasting information, and ADS-B Int, for receiving information. It has two advantages. One is that air traffic control can directly check aircraft information without asking. The other is that air traffic control can collect information sent by other aircraft for autonomous avoidance.

Because of the nature of broadcasting, such information is relatively easy to obtain, and websites such as VarFlight and FlightAware are based on the aggregation of such information to create flight tracking systems.

DecoHack — Indie developer inspiration weekly

Zhangferry: A weekly magazine for indie developers to help them find new products and new directions. Created by a Tencent designer, it is now in its 7th issue. There are many niche but beautiful apps to be found for developers to look for inspiration; It also shares technical tutorials, tax tips for starting a company, marketing tips and more.

There is also an interesting website found in this weekly: lofi.co/, which can simulate cafes, books…

Learning materials

Mimosa

Instant tutorial

Address: js. Design/courses

Curated design courses organized by the Real-time Design community, Real-time Design is a professional UI design tool for online real-time collaboration, similar to Figma. In real-time tutorials you can find free high quality lessons from creators on all major video platforms. From the beginning of the zero foundation step by step to do cases, advanced skills, everything, very suitable for the programmers who want to learn a little UI knowledge.

Tools recommended

CoderStar

Decode

Address: microcodingapps.com/products/de…

Software status: $8.99

Software Introduction:

Convert Xcode Interface Builder files (Xib and Storyboard files) to Swift source code.

About us

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.

Phase to recommend

IOS Fishing Weekly 48th issue

IOS Fishing Weekly 47

IOS Fishing Weekly issue 46

IOS Fishing Weekly 45th issue