FastStartup

FastStartup is a component startup framework designed to help developers easily and efficiently initialize various components. Making links FastStartup

If you are interested in looking at the source code project, then you can get something extra

  1. Learn about developing Gradle plug-ins using Booster
  2. Understand the development and debugging process of Gradle plug-in
  3. Learn about Gradle plugin packaging process and packaging scripts and publish tomavencenter
  4. Learn how a component is published tomavencenter

The code doesn’t have too much encapsulation, allowing you to experience the process as it really is.

1. Why write this component?

I’ve been thinking about this for a long time, and there are already many such components, so why write one?

  • Because they are still limited, some usage scenarios are not well supported
  • Complex to use, configuration interspersed with many places, many kinds, people feel confused
  • Uncoupling is not supported
  • There are reflections, IO
  • Privacy scenarios are not supported

Wait, although some aspects are not strictly malpractices, such as reflexes and IO. Although these methods theoretically increase the time, but in limited number of cases, the additional cost is not very large, the cost is small. But personally, I don’t think so. Because they don’t fit our scene.

Our component is Startup, positioning is at the time of application Startup, the Startup time will be very sensitive, big factory App has strict control on the Startup time, so a loss of overhead, can be avoided or avoided. There is also an additional memory overhead associated with reflection, which can be magnified when your App is large and complex, so I chose the original approach and hardcoded the list of components to maintain.

There are also startup parameters, although there are other ways to get some configuration at initialization, such as if you need a key for a task, this scenario is rarely supported by similar components.

FastStartup provides Application, isDebug, and Param (common parameters of Object type) for each task. It is extensible and gives you the most space to expand parameters.

Main thread waiting is supported. With this, you can execute all your tasks in child threads (unless the task must be executed in the main thread), and the main thread will wait until the task you want is finished.

In many scenarios, component dependencies can be complex, may be lost the initialization of a certain component or circular dependencies between components, therefore, specially made detection algorithm, can find missing components and circular dependencies scenarios to print out the dependencies between components of figure, let you be clear at a glance, found the problem quickly. It also supports printing all dependency diagrams by whomever.

I like the dependency configuration mode of App Startup, which is very convenient for componentization. For this purpose, WE provide the ASM peg mode, which relies on annotations to automatically complete component maintenance.

Decoupling adopts the form of automatic scan interface, automatic scan component dependent interface, maintain the relationship between interface class and component class, when you rely on the interface, internal can automatically find the corresponding component entity.

Internal use of thread pool, task completion after the next round of tasks reuse threads, rather than other schemes where all tasks start and then block, wait for dependency completion and wake up this scheme.

There are many other aspects of FastStartup that I won’t cover in detail

It took many nights and weekends to write this component, so please click Star if you can

2. Component features

Simple, efficient, support coupling. There are not too many startup configuration methods, just to provide a simple experience. No reflection, no IO operation, can provide you with the fastest start speed.

3. What can you get out of it?

  1. No reflection, no IO operation, providing the fastest startup speed
  2. Components only need to pay attention to other components on which they depend and automatically maintain the initialization sequence
  3. The component supports configuration to run on both UI threads and non-UI threads
  4. Support for UI thread wait operations, allowing the UI thread to block until necessary components are initialized, which can run in any thread
  5. Component initialization parameter configuration is supported. You can create an arbitrary configuration information that will be used throughout all component initialization operations
  6. Support decoupling, use interface for dependency management, avoid strong dependency between components, make your project more concise
  7. Support for automatic component injection, providing AN AOP solution that lets you automatically initialize components without having to deal with each one with only an annotation, and implement dependency as configuration
  8. Component completion callbacks are supported. There are three types of callbacks, one for each component initialization completion, one for the UI thread task completion, and one for all tasks completion
  9. Supports component initialization time statistics
  10. Support dependency missing detection and dependency cycle detection
  11. Support privacy mode startup, automatic initialization process according to component dependencies and whether the need for privacy mode startup, can be called again after the privacy permission is granted automatic execution of the remaining tasks
  12. Component dependency printing is supported

4. Dependency ring detection and deletion detection

When FastStartup is started, dependency and absence checks are automatically performed. If there is a dependency, an exception is thrown and the following information is printed

If the dependency is missing, the following message is printed

5. Time statistics

FastStartup may not be perfect, but hopefully it gives you an idea. If necessary, please mention issues to me. If you have other ideas, welcome to discuss together