头图

Author: drunken fairy

With the rapid development of Youku's business, there has been an explosive growth in the number of modules, which basically increases at the rate of a large number of new modules every year. So far, Youku has had a very large module dependency. Communication between modules is often directly dependent on each other, so that the coupling is very serious and confusing. Each library dependency is a "tree" or even a "net", which causes a lot of troubles in daily research and development:

Plug-in landing results

The iOS module plug-in has been fully implemented on Youku, and a large number of business and architecture plug-ins have been precipitated for each business line. Plug-in projects can be freely assembled in the future according to different business needs. The following are some of the benefits after the current plug-in project is implemented:

  • direct benefit

    • The compilation efficiency of business plug-in projects has been significantly improved, the local compilation time has been greatly reduced, and all related developments have been used;
    • Generate business plug-in projects through plug-in assembly, plug-in projects support simulator compilation and debugging, and support hot reloading;
    • Both the module project and the whole package project use plug-ins as dependencies, which completely solves the inconsistency of the module version of the module project and the whole package project, and supports the automatic update of the dependent module version;
    • The number of dependent libraries for the business plug-in project is greatly reduced, and the pod directly reuses the cache, which greatly improves the success rate and speed of the pod, and greatly reduces the disk usage;
  • indirect benefit

    • It can provide plug-in bayonets such as running memory, app startup, power consumption, etc., and maintain a good user experience in a normalized manner;
    • All plug-ins support free assembly, and through the configuration center, provide the ability to quickly incubate Express Edition, International Edition, Apple Watch, Apple TV and other apps;
    • Dependency is reduced, the module tree is quickly generated during swift breakpoint debugging, and the breakpoint efficiency is improved;
    • Speed up the packaging efficiency, establish a plug-in project construction platform, and test students can use the platform dynamic configuration to generate a plug-in combination installation package for testing.

what is a plugin

  • Plugins are aggregated from a set of modules and can also depend on other plugins. Physically, a plugin is a text description file that describes the modules and plugin information it contains;
  • The plug-in is based on the Xcode project, which can independently compile and generate App products, and supports the free combination of multiple plug-ins.

Simple plugin

A simple plugin can consist of just one module.

 # 图片库插件
target 'Plugin' do   
    #模块A
    pod '模块A','5.9.4' 
end

complex plugin

A complex plugin can consist of one or more plugins and modules.

 # 插件
target 'Plugin' do
    # 图片库插件
    plug '1.图片库插件'
  
    #webp图片解析模块
    pod '模块B','0.1.4' 
    #webp基础模块
    pod '模块C','1.1.0.1' 
end

Why do you need a plugin

After communicating with students from multiple business teams, we found that most businesses often only focus on the business functions that they need to iterate when debugging functions, and do not care about other businesses. So we thought that we could cut out an APP with only a single business function based on the whole package project, so that the compilation speed will definitely be greatly improved.

Tailoring an APP requires decoupling of modules. If decoupling is done according to the granularity of modules, the labor cost of decoupling a huge number of modules is too high, and excessive changes will also have a greater impact on online stability. Therefore, we have enlarged the decoupling granularity, from module decoupling granularity to plugin-based decoupling, so that we only need to decouple the horizontal coupling relationship between plugins and plugins, plugins are allowed to depend on other plugins downward, and The internal modules of the plug-in also allow mutual coupling, which greatly reduces the labor cost of decoupling, and facilitates subsequent maintenance of dependencies in the plug-in dimension.

Plugin usage specification

Plugin Aggregation Principle

  • Business plug-ins: business modules divide boundaries according to business function dimensions and aggregate into business plug-ins;
  • General business plug-ins: general business modules are divided into boundaries according to the minimum reusable set of services, and aggregated into general business plug-ins;
  • Architecture function plug-ins: Group middleware module, Youku middleware module, divide the boundary according to the minimum set of functions, and aggregate into architecture function plug-ins.

Plugin Dependency Principle

  • Business plugins are not allowed to depend on other business plugins horizontally, and are allowed to depend on lower-level plugins;
  • Architecture layer plugins are not allowed to depend on upper layer plugins, but are allowed to depend on lower layer plugins and other architecture plugins.

Module Attribution Principle

  • A module can only belong to one plug-in, and the function of the module needs to be clarified;
  • If the same module is depended on by multiple plugins, it is necessary to consider sinking the module as a plugin;
  • A module can be written as a plugin.

Plugin Versioning Principles

  • Each plugin has no concept of version;
  • Modules and versions in an integration area correspond to modules and versions in a set of plugins;
  • The modules and versions in a set of plugins are the same as the integration area of the online version by default, and can also be set and synchronized to the latest integration area or historical integration area.

Plug-in Hierarchy

Based on the above concepts and usage specifications of plug-ins, we carried out plug-in transformation of the Youku APP architecture, from the group middleware to the business layer, from the bottom-up decoupling and aggregation modules to form plug-ins, and finally precipitated a large number of plug-ins and the APP architecture of the following levels.

  • Business implementation layer: plug-in transformation of Youku's existing business, aggregating into multiple general business plug-ins, through business plug-ins and a small number of plug-ins such as general business plug-ins and architectural function plug-ins that it depends on, a lightweight business can be quickly combined APP, used to improve the speed of business Pod and development and debugging;
  • Business interface layer: horizontally decouple Youku's existing business to form multiple business interface plug-ins to support the horizontal decoupling of upper-layer business plug-ins;
  • General business plug-ins: general business modules are divided into boundaries according to the minimum reusable set of services, and aggregated into general business plug-ins;
  • Architecture function plug-ins: Group middleware module, Youku middleware module, divide the boundary according to the minimum set of functions, and aggregate into architecture function plug-ins.

Low cost control solution

All modules of Youku have been transformed into plug-ins. In order to prevent project corruption in the subsequent version iteration process, a low-cost control plan has been developed, which can automatically update plug-in content and control plug-in dependencies.

Plugins are automatically updated

The content of the plug-in mainly includes the module name and module version number. For each version iteration, the plug-in faces the problems of adding, deleting, changing the name, and changing the version of the module in the plug-in. Each version of Youku integrates a large number of modules. If all of them are manually maintained , the cost will be very huge, so we have deployed a set of automatic synchronization and inspection services, mainly for the following purposes:

  • Added and deleted modules are automatically updated in the plugin;
  • The module version number in the plugin is automatically changed;
  • After the plugin content update is completed, all plugins are automatically compiled and inspected;
  • If the inspection passes, the plug-in is merged into the plug-in project integration branch for use by the business plug-in project;
  • If the inspection fails, DingTalk notifies the failure information (name of the failed plugin, link to the log of the compilation failure, and the plugin's new module prompt) to the DingTalk group, which is convenient for quick troubleshooting.

Plugin dependency management

We abstract the standard module dependency data based on the attribution and level of the plug-in, and then add the dependency detection checkpoint when the module is built and packaged. During each module construction process, the dependency checkpoint is executed, and only the plug-ins that pass the dependency check to be packaged.

Result data presentation

Build efficiency

The local compilation efficiency of the business plug-in project is compared with the whole package project:

  • The local compilation efficiency has been greatly improved, the average efficiency has been significantly improved, the local compilation time has been greatly reduced, and all related developments have been used.

Calculation formula:

  • Compilation efficiency improvement formula: local compilation efficiency improvement = (construction time of the whole package project - construction time of the business plug-in project) / construction time of the whole package project
  • Time saving formula: Compilation time saved per month (8 hours working days) = Number of monthly compilations of plug-in projects Average time saved per compilation (seconds) / (60 60 * 8)

Emulator support

There are some modules in Youku that do not support simulators, resulting in that the entire Youku package does not support simulators. After the plug-in transformation, when the business assembles its own business debugging project through plug-ins, this part of the plug-ins that do not support simulators is removed, so that the business plug-in project can be Use the emulator to debug. Emulator advantages:

  • An enterprise number is limited to 100 devices for real machine debugging, while the simulator is unlimited;
  • The simulator supports all iOS systems, and the development and testing costs for some old systems are low;
  • The simulator supports hot reloading without compiling and re-running, and the modified code will take effect immediately after saving;
  • Adapt to the UI of new iOS models in advance.

Disk usage

Before the plug-in transformation of modules, we can only use the whole package project for development. When using the whole package project for daily development, all modules need to be downloaded. After the plug-in transformation is completed, we have split the whole package project. For a business plug-in project, the number of modules of the plug-in project is greatly reduced compared with the whole package project, and the disk usage of the plug-in project is greatly reduced compared with the whole package project. The following figure shows the disk size comparison between the whole package project and some business plug-in projects:

memory usage

Plug-in can provide plug-in checkpoints such as running memory, app startup, power consumption, etc., and normalization maintains a good user experience. Taking the running memory of the play page as an example, the play page has functions such as player, page container, barrage, and comment. In the past, the memory value was calculated for the entire play page, but now the memory value can be calculated according to the fine-grained function, and the memory value of the player plug-in, play page container plug-in, bullet screen plug-in, and comment plug-in can be obtained respectively.

Epilogue

To sum up, the plug-in of iOS engineering is to use the idea of divide and conquer to divide a complex app into multiple sub-apps. Through sub-apps, R&D can be focused on demand R&D and user experience improvement. At the same time, the plug-in disassembly feature also improves the efficiency of troubleshooting online reproducible problems. Therefore, plug-in is very helpful for R&D efficiency and the improvement of development happiness.

Pay attention to [Alibaba Mobile Technology], Ali's cutting-edge mobile dry goods & practice will give you thoughts!


阿里巴巴终端技术
336 声望1.3k 粉丝

阿里巴巴移动&终端技术官方账号。