Allow to disable ensureAccess() on every method call for performance rea...

...sons.

Motiviation:

At the moment we use AbstractByteBuf.ensureAccess() on every operation which is quite heavy in terms of performance hit. Especially as it is "only" a safety check and nothing more. We should allow to limit the usage of it.

Modification:

- Add System property io.netty.buffer.ensureAccess which allows to disable it
- Check for ensureAccess() in DefaultChannelHandlerContext all the time to not completily disable safety.

Result:

Give a nice performance boost in benchmarks.
Yes I did... Performance impact is negible. But the performance boost of when disable ENSURE_ACCESS is very notable. Also I bever heard that instanceof is expensive. IMHO it is very cheap

> Am 20.07.2014 um 10:43 schrieb Idel Pivnitskiy <notifications@github.com>:
> 
> In common/src/main/java/io/netty/util/ReferenceCountUtil.java:
> 
> > @@ -94,6 +94,18 @@ public static boolean release(Object msg, int decrement) {
> >      }
> >  
> >      /**
> > +     * Will throw a {@link IllegalReferenceCountException} if the specified object is of type
> > +     * {@link ReferenceCounted} and {@link ReferenceCounted#refCnt()} is {@code 0}.
> > +     */
> > +    public static void ensureAccessible(Object msg) {
> > +        if (msg instanceof ReferenceCounted) {
> > +            if (((ReferenceCounted) msg).refCnt() == 0) {
> > +                throw new IllegalReferenceCountException(0);
> > +            }
> > +        }
> > +    }
> I heared that instanceof is expensive.
> Did you measure performance when ENSURE_ACCESS == true? It is very interesting to see the difference between old and current implementations.
> 
> —
> Reply to this email directly or view it on GitHub.