Skip to content

Commit

Permalink
Add compile-only library for performance optimizations
Browse files Browse the repository at this point in the history
The new library has two artifacts:
- performance-annotation that provides an Android-specified annotation
  to selectively disable inlining in ART. The @NeverInline annotation
  must use the exact package name and class name it uses but it's only
  realized on Android targets, following the same expect/actual pattern
  used by Kotlin's built-in annotations (@JvmInline for instance).
- performance-unsafe to allow Android targets to compile against the
  sun.misc.Unsafe API.

These two artifacts are compile-only and not published. They are for
internal use only.

Relnote: N/A
Test: N/A
Change-Id: I6c2b6eaeedd61c2a020cf38220d971075fe3c01c
  • Loading branch information
romainguy committed Oct 11, 2024
1 parent 56f6328 commit 2f71d5f
Show file tree
Hide file tree
Showing 11 changed files with 377 additions and 5 deletions.
5 changes: 2 additions & 3 deletions compose/OWNERS
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Bug component: 612128
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
4 changes: 2 additions & 2 deletions graphics/OWNERS
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Bug component: 1137062
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
2 changes: 2 additions & 0 deletions performance/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[email protected]
[email protected]
1 change: 1 addition & 0 deletions performance/performance-annotation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This library is a **compile-time** only dependency.
69 changes: 69 additions & 0 deletions performance/performance-annotation/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import androidx.build.KotlinTarget
import androidx.build.PlatformIdentifier
import androidx.build.Publish
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile

plugins {
id("AndroidXPlugin")
id("com.android.library")
}

androidXMultiplatform {
android()
jvm()
mac()
linux()
ios()
watchosDeviceArm64()
watchos()
tvos()
mingwX64()

defaultPlatform(PlatformIdentifier.JVM)

sourceSets {
commonMain {
dependencies {
api(libs.kotlinStdlib)
}
}

androidMain {
dependsOn(commonMain)
}

// Workaround for https://youtrack.jetbrains.com/issue/KT-51763
// Make sure commonization runs before any compilation task.
tasks.withType(KotlinNativeCompile).configureEach {
it.dependsOn(tasks.named("commonize"))
}
}
}

android {
namespace = "androidx.performance.annotation"
}

androidx {
name = "Performance - Annotation"
publish = Publish.NONE
inceptionYear = "2024"
description = "Provides source annotations for performance optimizations."
kotlinTarget = KotlinTarget.KOTLIN_1_9
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dalvik.annotation.optimization

@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.CONSTRUCTOR, AnnotationTarget.FUNCTION)
public actual annotation class NeverInline()
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

@file:OptIn(ExperimentalMultiplatform::class)

package dalvik.annotation.optimization

/**
* Indicates that an API should never be inlined by ART on Android.
*
* [NeverInline] can be used to annotate methods that should not be inlined into other methods.
* Methods that are not called frequently, are never speed-critical, or are only used for debugging
* do not necessarily need to run quickly. Applying this annotation to prevent these methods from
* being inlined will return some size improvements in .odex files.
*
* Prefer using the `AndroidNeverInline` typealias instead of this annotation directly to emphasize
* it only affects Android targets.
*/
@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.CONSTRUCTOR, AnnotationTarget.FUNCTION)
@OptionalExpectation
public expect annotation class NeverInline()
2 changes: 2 additions & 0 deletions performance/performance-unsafe/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This library is a **compile-time** only dependency for Android.
It is not to be used for other targets.
34 changes: 34 additions & 0 deletions performance/performance-unsafe/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import androidx.build.Publish

plugins {
id("AndroidXPlugin")
id("java-library")
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

androidx {
name = "Performance - Unsafe"
publish = Publish.NONE
inceptionYear = "2024"
description = "Compile-time support for sun.misc.Unsafe."
}
Loading

0 comments on commit 2f71d5f

Please sign in to comment.