mdedetrich commented on code in PR #2409: URL: https://github.com/apache/pekko/pull/2409#discussion_r2472754494
########## stream/src/main/scala/org/apache/pekko/stream/impl/io/compression/ZstdCompressor.scala: ########## @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.pekko.stream.impl.io.compression + +import java.nio.ByteBuffer + +import com.github.luben.zstd.{ Zstd, ZstdDictCompress, ZstdDirectBufferCompressingStreamNoFinalizer } + +import org.apache.pekko +import pekko.annotation.InternalApi +import pekko.util.ByteString + +/** INTERNAL API */ +@InternalApi private[pekko] class ZstdCompressor( + compressionLevel: Int = + Zstd.defaultCompressionLevel(), dictionary: Option[ZstdDictCompress] = None) extends Compressor { + + private val targetBuffer = ByteBuffer.allocateDirect(65536) + private val compressingStream = new ZstdDirectBufferCompressingStreamNoFinalizer(targetBuffer, compressionLevel) + + dictionary.foreach(compressingStream.setDict) + + override def compress(input: ByteString): ByteString = { + val inputBB = ByteBuffer.allocateDirect(input.size) Review Comment: Possibly? I just read the implementation now and it appears that the main use case of `ByteBufferPool ` is if you need a pool of buffers where as in our case we only have a static set amount of direct byte buffers and they have different sizes. However from reading the `ByteBufferPool` code I did found another improvement, we can use `ByteBufferCleaner.clean(byteBuffer)` to clean up the byte buffers in a timely manner (will implement this). -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
