PERFORMANCE: Lucene.Net.Core.Store (FSDirectory + SimpleFSDirectory): Removed chunking from read and write operations, since FileStream already takes care of this (better)
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/f78116a4 Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/f78116a4 Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/f78116a4 Branch: refs/heads/api-work Commit: f78116a4fae11a9ba130cccff543065aa8254554 Parents: 3724588 Author: Shad Storhaug <[email protected]> Authored: Fri Mar 24 08:59:03 2017 +0700 Committer: Shad Storhaug <[email protected]> Committed: Fri Mar 24 08:59:03 2017 +0700 ---------------------------------------------------------------------- src/Lucene.Net.Core/Store/FSDirectory.cs | 36 +++++++++++-------- src/Lucene.Net.Core/Store/SimpleFSDirectory.cs | 39 ++++++++++++--------- 2 files changed, 45 insertions(+), 30 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucenenet/blob/f78116a4/src/Lucene.Net.Core/Store/FSDirectory.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Store/FSDirectory.cs b/src/Lucene.Net.Core/Store/FSDirectory.cs index 7627eb7..3530799 100644 --- a/src/Lucene.Net.Core/Store/FSDirectory.cs +++ b/src/Lucene.Net.Core/Store/FSDirectory.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq;// Used only for WRITE_LOCK_NAME in deprecated create=true case: @@ -463,11 +464,12 @@ namespace Lucene.Net.Store /// </summary> protected class FSIndexOutput : BufferedIndexOutput { - /// <summary> - /// The maximum chunk size is 8192 bytes, because <seealso cref="RandomAccessFile"/> mallocs - /// a native buffer outside of stack if the write buffer size is larger. - /// </summary> - private const int CHUNK_SIZE = 8192; + // LUCENENET specific: chunk size not needed + ///// <summary> + ///// The maximum chunk size is 8192 bytes, because <seealso cref="RandomAccessFile"/> mallocs + ///// a native buffer outside of stack if the write buffer size is larger. + ///// </summary> + //private const int CHUNK_SIZE = 8192; private readonly FSDirectory parent; internal readonly string name; @@ -475,7 +477,7 @@ namespace Lucene.Net.Store private volatile bool isOpen; // remember if the file is open, so that we don't try to close it more than once public FSIndexOutput(FSDirectory parent, string name) - : base(CHUNK_SIZE) + : base(/*CHUNK_SIZE*/) { this.parent = parent; this.name = name; @@ -485,14 +487,20 @@ namespace Lucene.Net.Store protected internal override void FlushBuffer(byte[] b, int offset, int size) { - //Debug.Assert(IsOpen); - while (size > 0) - { - int toWrite = Math.Min(CHUNK_SIZE, size); - file.Write(b, offset, toWrite); - offset += toWrite; - size -= toWrite; - } + Debug.Assert(isOpen); + //while (size > 0) + //{ + // int toWrite = Math.Min(CHUNK_SIZE, size); + // file.Write(b, offset, toWrite); + // offset += toWrite; + // size -= toWrite; + //} + + // LUCENENET specific: FileStream is already optimized to write natively + // if over the buffer size that is passed through its constructor. So, + // all we need to do is Write(). + file.Write(b, offset, size); + //Debug.Assert(size == 0); } http://git-wip-us.apache.org/repos/asf/lucenenet/blob/f78116a4/src/Lucene.Net.Core/Store/SimpleFSDirectory.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Core/Store/SimpleFSDirectory.cs b/src/Lucene.Net.Core/Store/SimpleFSDirectory.cs index 2a93d8c..22b778d 100644 --- a/src/Lucene.Net.Core/Store/SimpleFSDirectory.cs +++ b/src/Lucene.Net.Core/Store/SimpleFSDirectory.cs @@ -118,11 +118,12 @@ namespace Lucene.Net.Store /// </summary> protected internal class SimpleFSIndexInput : BufferedIndexInput { - /// <summary> - /// The maximum chunk size is 8192 bytes, because <seealso cref="RandomAccessFile"/> mallocs - /// a native buffer outside of stack if the read buffer size is larger. - /// </summary> - private const int CHUNK_SIZE = 8192; + // LUCENENET specific: chunk size not needed + ///// <summary> + ///// The maximum chunk size is 8192 bytes, because <seealso cref="RandomAccessFile"/> mallocs + ///// a native buffer outside of stack if the read buffer size is larger. + ///// </summary> + //private const int CHUNK_SIZE = 8192; /// <summary> /// the file channel we will read from </summary> @@ -195,17 +196,23 @@ namespace Lucene.Net.Store try { - while (total < len) - { - int toRead = Math.Min(CHUNK_SIZE, len - total); - int i = m_file.Read(b, offset + total, toRead); - if (i < 0) // be defensive here, even though we checked before hand, something could have changed - { - throw new EndOfStreamException("read past EOF: " + this + " off: " + offset + " len: " + len + " total: " + total + " chunkLen: " + toRead + " end: " + m_end); - } - Debug.Assert(i > 0, "RandomAccessFile.read with non zero-length toRead must always read at least one byte"); - total += i; - } + //while (total < len) + //{ + // int toRead = Math.Min(CHUNK_SIZE, len - total); + // int i = m_file.Read(b, offset + total, toRead); + // if (i < 0) // be defensive here, even though we checked before hand, something could have changed + // { + // throw new EndOfStreamException("read past EOF: " + this + " off: " + offset + " len: " + len + " total: " + total + " chunkLen: " + toRead + " end: " + m_end); + // } + // Debug.Assert(i > 0, "RandomAccessFile.read with non zero-length toRead must always read at least one byte"); + // total += i; + //} + + // LUCENENET specific: FileStream is already optimized to read natively + // using the buffer size that is passed through its constructor. So, + // all we need to do is Read(). + total = m_file.Read(b, offset, len); + Debug.Assert(total == len); } catch (System.IO.IOException ioe)
