You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucenenet.apache.org by "Van Den Berghe, Vincent" <Vi...@bvdinfo.com> on 2017/02/28 07:21:16 UTC

Performance improvement for Lucene.net with memory mapped files (bis)

Further testing has indicated that mapped memory accessors will throw an exception if the position argument is already at the end, even if zero bytes are read.
The methods mentioned previously therefore become:

              public override ByteBuffer Get(byte[] dst, int offset, int length)
              {
                     CheckBounds(offset, length, dst.Length);
                     if (length > Remaining)
                           throw new BufferUnderflowException();
                     // we need to check for 0-length reads, since ReadArray will throw an ArgumentOutOfRange exception if position is at the end
                     // even when nothing is read
                     if (length > 0)
                           _accessor.ReadArray(Ix(NextGetIndex(length)), dst, offset, length);
                     return this;
              }


And

              public override ByteBuffer Put(byte[] src, int offset, int length)
              {
                     CheckBounds(offset, length, src.Length);
                     if (length > Remaining)
                           throw new BufferOverflowException();
                     // we need to check for 0-length writes, since ReadArray will throw an ArgumentOutOfRange exception if position is at the end
                     // even when nothing is read
                     if (length > 0)
                           _accessor.WriteArray(Ix(NextPutIndex(length)), src, offset, length);
                     return this;
              }


Vincent

Re: Performance improvement for Lucene.net with memory mapped files (bis)

Posted by "Oren Eini (Ayende Rahien)" <ay...@ayende.com>.
Better to move the throw to a dedicated method, it generates better code
this way

*Hibernating Rhinos Ltd  *

Oren Eini* l CEO l *Mobile: + 972-52-548-6969

Office: +972-4-622-7811 *l *Fax: +972-153-4-622-7811



On Tue, Feb 28, 2017 at 9:21 AM, Van Den Berghe, Vincent <
Vincent.VanDenBerghe@bvdinfo.com> wrote:

> Further testing has indicated that mapped memory accessors will throw an
> exception if the position argument is already at the end, even if zero
> bytes are read.
> The methods mentioned previously therefore become:
>
>               public override ByteBuffer Get(byte[] dst, int offset, int
> length)
>               {
>                      CheckBounds(offset, length, dst.Length);
>                      if (length > Remaining)
>                            throw new BufferUnderflowException();
>                      // we need to check for 0-length reads, since
> ReadArray will throw an ArgumentOutOfRange exception if position is at the
> end
>                      // even when nothing is read
>                      if (length > 0)
>                            _accessor.ReadArray(Ix(NextGetIndex(length)),
> dst, offset, length);
>                      return this;
>               }
>
>
> And
>
>               public override ByteBuffer Put(byte[] src, int offset, int
> length)
>               {
>                      CheckBounds(offset, length, src.Length);
>                      if (length > Remaining)
>                            throw new BufferOverflowException();
>                      // we need to check for 0-length writes, since
> ReadArray will throw an ArgumentOutOfRange exception if position is at the
> end
>                      // even when nothing is read
>                      if (length > 0)
>                            _accessor.WriteArray(Ix(NextPutIndex(length)),
> src, offset, length);
>                      return this;
>               }
>
>
> Vincent
>