luyuncheng commented on code in PR #987: URL: https://github.com/apache/lucene/pull/987#discussion_r923284236
########## lucene/core/src/java/org/apache/lucene/codecs/lucene90/compressing/Lucene90CompressingStoredFieldsWriter.java: ########## @@ -519,7 +518,13 @@ private void copyOneDoc(Lucene90CompressingStoredFieldsReader reader, int docID) assert reader.getVersion() == VERSION_CURRENT; SerializedDocument doc = reader.document(docID); startDocument(); - bufferedDocs.copyBytes(doc.in, doc.length); + + if (doc.in instanceof ByteArrayDataInput) { + // reuse ByteArrayDataInput to reduce memory copy + bufferedDocs.copyBytes((ByteArrayDataInput) doc.in, doc.length); + } else { + bufferedDocs.copyBytes(doc.in, doc.length); + } Review Comment: > I think that we could avoid this `instanceof` check by overriding `ByteBuffersDataOutput#copyBytes` to read directly into its internal buffers when they are not direct (ie. backed by a `byte[]`)? (Maybe in a separate change?) @jpountz thanks for your advice! i think overriding `ByteBuffersDataOutput#copyBytes` is a great idea, it can reduce many method do memory copy I opened a new issue: LUCENE-10657 #1034 i think when we move this logic into `ByteBuffersDataOutput#copyBytes` it can reduce more memory copy method: 1. Reduce memory copy in Lucene90CompressingStoredFieldsWriter#copyOneDoc -> bufferdDocs.copyBytes(DataInput input) 2. Reduce memory copy in Lucene90CompoundFormat.writeCompoundFile -> data.copyBytes when input is BufferedChecksumIndexinput and output is ByteBuffersDataOutput 3. Reduce memory IndexWriter#copySegmentAsIs ->CopyFrom -> copyBytes -- 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: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org