Conscrypt class initialization performs resource I/O, adding 50 ms–3 s to app startup
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 半日
- 初心者へのやさしさ
- 45/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- java
調査の方向性
Read common/src/main/java/org/conscrypt/Conscrypt.java and the build script that currently generates conscrypt.properties; identify where version constants can be generated at build time. Update the version-loading path and verify that Conscrypt.version() still returns the expected values and that class initialization performs no resource I/O. The issue provides a fork commit for comparison, but it also states that external pull requests are not currently accepted.
索引モデルが issue の本文から書いたものです。
説明
Summary
org.conscrypt.Conscrypt reads conscrypt.properties via
Class.getResourceAsStream() in its static initializer. Because this runs
during class initialization, the resource lookup and property parsing happen
on whichever thread first initializes Conscrypt — in Android apps this is
often the UI thread during provider setup.
Impact (measured in our app)
- Typical phones: about +50 ms cold app startup.
- Low-end TV boxes: about +2–3 s cold app startup.
- The cost is paid unconditionally, even when
Conscrypt.version()is never
called.
Measured on release builds using cold start (adb shell am start -W, averaged
over several runs). Removing the lookup removes the delta. We can share
traces/methodology if useful.
Root cause
common/src/main/java/org/conscrypt/Conscrypt.java:
private static final Version VERSION;
static {
int major = -1;
int minor = -1;
int patch = -1;
InputStream stream = null;
try {
stream = Conscrypt.class.getResourceAsStream("conscrypt.properties");
if (stream != null) {
Properties props = new Properties();
props.load(stream);
major = Integer.parseInt(props.getProperty("org.conscrypt.version.major", "-1"));
minor = Integer.parseInt(props.getProperty("org.conscrypt.version.minor", "-1"));
patch = Integer.parseInt(props.getProperty("org.conscrypt.version.patch", "-1"));
}
} catch (IOException e) {
// ...
} finally {
IoUtils.closeQuietly(stream);
}
// VERSION = ...
}
getResourceAsStream() triggers a classloader resource lookup (APK/zip
lookup and stream setup), then Properties.load() parses the stream — all
on the calling thread inside <clinit>.
Suggested fix
Generate the version as compile-time constants at build time. The build script
that currently generates conscrypt.properties would emit:
// Generated from the Gradle project version. Do not edit.
package org.conscrypt;
final class ConscryptVersion {
static final int MAJOR = 2;
static final int MINOR = 10;
static final int PATCH = 0;
private ConscryptVersion() {}
}
and Conscrypt.java would use:
private static final Version VERSION = new Version(
ConscryptVersion.MAJOR, ConscryptVersion.MINOR, ConscryptVersion.PATCH);
Because the values are static final int constants, javac inlines them, so
<clinit> contains only a few iconst/putstatic instructions and performs
no I/O. The version still stays in sync with build.gradle for both the
OpenJDK and Android artifacts.
A less invasive alternative is to move the lookup into an
initialization-on-demand holder, so merely loading Conscrypt does no I/O
and the properties are read only on the first version() call.
Additional notes
conscrypt.propertiesis only consumed byConscrypt.java
(org.conscrypt.version.*), so it can be replaced by generated constants.- The current code silently returns a
nullversion if the resource is
missing or unreadable, so the runtime resource is not a reliable source
even today. - I understand external PRs are no longer accepted; filing this for
consideration. A patch against current master is available on my fork:
https://github.com/wuyisheng/conscrypt/commit/76fa451e13c0bed9fb7f1a1a33679208c6d274f2
- 主要言語
- Java
- スター
- 1.4k
- フォーク
- 332
- 平均マージ
- 2日 56分
- マージ済み PR(30日)
- 5
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
google/conscrypt のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 49/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 22/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 58/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
google/conscrypt の issue をすべて見る
似ている issue
-
beginner difficulty: easy documentation good first issue hacktoberfest help wanted observability size/S up-for-grabs
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
dmitriy-iliyov/spring-transactional-outbox#82 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
RamazanKara/nightjar#264 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
netty/netty#18628 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 87/100
apache/flink-agents#1500 ·
メンテナーはふだん 1 日以内に返信
-
bug frontend
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
sylvainmetayer/planning-equipes#495 ·
メンテナーはふだん 1 日以内に返信