You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@pekko.apache.org by "pjfanning (via GitHub)" <gi...@apache.org> on 2026/07/06 12:30:18 UTC
[PR] [WIP] use ByteString toArrayUnsafe in new deflater code [pekko-http]
pjfanning opened a new pull request, #1135:
URL: https://github.com/apache/pekko-http/pull/1135
Code looks like it should be ok to use toArrayUnsafe, that no other code should be able to modify the array data.
toArrayUnsafe() on ByteString is only really helpful for ByteStrings directly based by 1 byte array with no offset. Otherwise, it gives you the same as toArray.
I don't know if the costs outweigh the benefits but if used an InflaterInputStream, we can get an InputStream from a ByteString that can avoid array copies for all ByteString types - but with extra expense to manage the stream, etc.
`new InflaterInputStream(byteString.asInputStream)`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org
Re: [PR] use ByteString toArrayUnsafe in new deflater code [pekko-http]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on PR #1135:
URL: https://github.com/apache/pekko-http/pull/1135#issuecomment-4893079677
@mkurz does this look ok?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org
Re: [PR] use ByteString toArrayUnsafe in new deflater code [pekko-http]
Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on code in PR #1135:
URL: https://github.com/apache/pekko-http/pull/1135#discussion_r3529117728
##########
http-core/src/main/scala/org/apache/pekko/http/impl/engine/ws/PerMessageDeflate.scala:
##########
@@ -194,7 +194,7 @@ private[http] object PerMessageDeflate {
private def inflate(data: ByteString, appendTail: Boolean): ByteString = {
try {
val input = if (appendTail) data ++ EmptyStoredBlock else data
- inflater.setInput(input.toArray)
+ inflater.setInput(input.toArrayUnsafe())
Review Comment:
can we use the asInputStream here
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org
Re: [PR] use ByteString toArrayUnsafe in new deflater code [pekko-http]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on code in PR #1135:
URL: https://github.com/apache/pekko-http/pull/1135#discussion_r3529219525
##########
http-core/src/main/scala/org/apache/pekko/http/impl/engine/ws/PerMessageDeflate.scala:
##########
@@ -194,7 +194,7 @@ private[http] object PerMessageDeflate {
private def inflate(data: ByteString, appendTail: Boolean): ByteString = {
try {
val input = if (appendTail) data ++ EmptyStoredBlock else data
- inflater.setInput(input.toArray)
+ inflater.setInput(input.toArrayUnsafe())
Review Comment:
actually it's CRC32 that is what uses the bytes from the ByteString not the Inflater directly
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org
Re: [PR] use ByteString toArrayUnsafe in new deflater code [pekko-http]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on code in PR #1135:
URL: https://github.com/apache/pekko-http/pull/1135#discussion_r3529137741
##########
http-core/src/main/scala/org/apache/pekko/http/impl/engine/ws/PerMessageDeflate.scala:
##########
@@ -194,7 +194,7 @@ private[http] object PerMessageDeflate {
private def inflate(data: ByteString, appendTail: Boolean): ByteString = {
try {
val input = if (appendTail) data ++ EmptyStoredBlock else data
- inflater.setInput(input.toArray)
+ inflater.setInput(input.toArrayUnsafe())
Review Comment:
would need something like `new InflaterInputStream(byteString.asInputStream)`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org
Re: [PR] use ByteString toArrayUnsafe in new deflater code [pekko-http]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning merged PR #1135:
URL: https://github.com/apache/pekko-http/pull/1135
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org
Re: [PR] use ByteString toArrayUnsafe in new deflater code [pekko-http]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on code in PR #1135:
URL: https://github.com/apache/pekko-http/pull/1135#discussion_r3529549083
##########
http-core/src/main/scala/org/apache/pekko/http/impl/engine/ws/PerMessageDeflate.scala:
##########
@@ -275,15 +275,15 @@ private[http] object PerMessageDeflate {
}
private def deflate(data: ByteString, removeTail: Boolean): ByteString = {
- deflater.setInput(data.toArray)
- val output = new ByteArrayOutputStream()
+ deflater.setInput(data.toArrayUnsafe())
+ val output = new ByteArrayOutputStream(1024)
Review Comment:
ByteArrayOutputStream starts with 32 bytes by default and you can end up allocating multiple new arrays while you grow the data. Starting with a reasonable value can help.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org