Skip to content

This is an Android plugin, which can improve the performance of layout loading by parsing the layout xml file during the compilation period and converting the reflection instantiation in LayoutInflater into a normal instantiation. 这是一个Android插件,通过在编译期时解析布局xml文件,将LayoutInflater中的反射实例化转成普通的实例化,以此来提高布局加载的性能

License

Notifications You must be signed in to change notification settings

dreamgyf/FastInflate

Repository files navigation

Android Kotlin Gradle Maven CI version stars LICENSE

English | 中文

This is an Android plugin, which can improve the performance of layout loading by parsing the layout xml file during the compilation period and converting the reflection instantiation in LayoutInflater into a normal instantiation.

Get Started

Dependencies

  1. Open the setting.gradle file, and make sure that the repositories, gradlePluginPortal and mavenCentral, are configured.
pluginManagement {
    repositories {
        gradlePluginPortal()
        mavenLocal()
        // other repository
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        mavenCentral()
        mavenLocal()
        // other repository
    }
}
  1. Open the build.gradle file of project, and add the FastInflate plugin in the plugins.
plugins {
    id 'com.dreamgyf.android.fastinflate' version '0.1.0-alpha-07' apply false
}
  1. Open the build.gradle file of module, and add the FastInflate plugin in the plugins.
plugins {
    id 'com.dreamgyf.android.fastinflate'
}
  1. Open the build.gradle file of module, and add the FastInflate library in the dependencies.
dependencies {
    implementation 'com.dreamgyf.android.fastinflate:0.1.0-alpha-07'
}

Usage

Just use FastInflate instead LayoutInflater.

// LayoutInflater.from(this).inflate(R.layout.activity_main, null)
FastInflate.from(this).inflate(R.layout.activity_main, null)

Notice

  • The <include /> tag doesn't supported to use theme attribute.

  • The current version is an alpha beta, and have not done compatibility tests for all of the Android versions.

Performance test

After fixing the context problem, the performance drops to the same level as that of the LayoutInflater.

I'll find ways to improve performance in the future.

Repositories

LICENSE

This project uses the Apache-2.0 license.

About

This is an Android plugin, which can improve the performance of layout loading by parsing the layout xml file during the compilation period and converting the reflection instantiation in LayoutInflater into a normal instantiation. 这是一个Android插件,通过在编译期时解析布局xml文件,将LayoutInflater中的反射实例化转成普通的实例化,以此来提高布局加载的性能

Topics

Resources

License

Stars

Watchers

Forks

Languages