Skip to content

HBASE-30391 Reduce array copying on expanding ByteArrayOutputStream - #8660

Open
Huginn-kio wants to merge 1 commit into
apache:masterfrom
Huginn-kio:HBASE-30391
Open

Huginn-kio wants to merge 1 commit into
apache:masterfrom
Huginn-kio:HBASE-30391

Conversation

@Huginn-kio

Copy link
Copy Markdown
Contributor

HBASE-30391

Summary

When ByteArrayOutputStream expands, it copies the entire backing array, including unused capacity. This change limits the copy to the bytes already written.

See https://issues.apache.org/jira/browse/HBASE-30391

Root cause

ByteArrayOutputStream.checkSizeAndGrow copied buf.length bytes when allocating a larger backing array, although only pos bytes contain valid stream data.

Fix

Copy only pos bytes during expansion. This preserves the stream contents while avoiding copies of unused capacity and reducing heap copy work.

Testing

  • mvn -pl hbase-common -am -DskipTests compile with JDK 17: BUILD SUCCESS.
  • Targeted Checkstyle for ByteArrayOutputStream.java: BUILD SUCCESS.
  • The full reactor quality check was also attempted; it is currently blocked by pre-existing InterfaceIsType violations in untouched hbase-annotations test interfaces.

Compatibility

  • No public API, configuration, persistence-format, or wire-format changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant