一句话:提出 TwinString,将字符串数据置于堆外,同时保持 java.lang.String 语义与 API 兼容。
Java 应用需从文件、数据库、网络等大量摄入文本。现有方案要么物化为堆上 String,带来分配、拷贝、编码和 GC 开销;要么使用低层外部内存 API,需非标准字符串接口并手动管理内存与生命周期。TwinString 将字符串语义与物理存储解耦:数据置于 Java 堆外,但保持标准 String 类型与行为,由 VM 控制并经 GC 管理生命周期,无需自定义字符串类型。作者在 GraalVM Native Image 中实现,并用微基准、真实文本处理及 JDBC、SQLite 负载评估。结果显示其显著降低分配开销,兼容原 String API,并在真实库与 JDBC 负载中将 P99.9 尾延迟最多降低 42.2%。
Strings are the primary mechanism through which Java applications ingest external textual data, including data read from files, databases, network interfaces, and native libraries. In data-intensive applications, such data must either be materialized as heap-allocated java.lang.String objects, incurring allocation, copying, encoding, and garbage-collection costs, or accessed through low-level and unsafe foreign-memory mechanisms that require non-standard string APIs and explicit reasoning about memory management and object lifetimes. Neither option is well suited to high-volume ingestion workloads that require both efficiency and seamless integration with existing Java code. We present TwinString, an alternative representation of java.lang.String that decouples string semantics from the physical placement of its contents. A TwinString stores its data outside the regular Java heap while preserving the standard String type and behavior expected by Java programs and libraries. VM support controls this data and manages its lifetime with garbage collection, allowing foreign textual data to be exposed as ordinary strings without introducing additional custom string types. We implement TwinStrings in GraalVM Native Image and evaluate them across several workloads, including microbenchmarks, text-processing applications over real-world datasets, and data-heavy applications using JDBC and SQLite. The results show that TwinStrings significantly reduce allocation overhead while remaining compatible with the original String API, and reduce P99.9 tail latency by up to 42.2% in realistic library and JDBC workloads by alleviating heap allocation and garbage-collection pressure.
@article{paperbot12135,
title = {TwinString: Preserving String Semantics with Off-Heap Data on the JVM},
author = {Júnior Löff and Daniele Bonetta and Walter Binder},
journal = {Proceedings of the ACM on Programming Languages},
volume = {10},
number = {OOPSLA2},
year = {2026},
doi = {10.1145/3839503}
}