db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Knut Anders Hatlen <Knut.Hat...@Sun.COM>
Subject Re: ArrayInputStream and performance
Date Tue, 28 Nov 2006 20:09:43 GMT
Daniel John Debrunner <djd@apache.org> writes:

> Knut Anders Hatlen wrote:
>> Daniel John Debrunner <djd@apache.org> writes:
>>> Knut Anders Hatlen wrote:
>>>> I can't answer your question, but I will add that I find much of the
>>>> code that uses ArrayInputStream very confusing. ArrayInputStream is
>>>> supposed to wrap a byte array to provide encapsulation and easy access
>>>> to the data through the InputStream interface. However, many (most?)
>>>> of the callers inline the accesses to the data (presumably for
>>>> performance reasons), so we end up with lots of methods looking like
>>>> this:
>>>>   public X readSomething(ArrayInputStream ais, byte[] data, int offset...)
>>>>     // lots of direct manipulation of the byte array
>>>>     // ...
>>>>     // ...
>>>>     // ...
>>>>     // finally, make sure that the state of the stream is brought to a
>>>>     // consistent state:
>>>>     ais.setPosition(offset + numberOfManipulatedBytes);
>>>>   }
>>> I could only find one method that looked something like the above:
>>> StoredFieldHeader.readFieldLengthAndSetStreamPosition
>>> Could you provide a list of the others so I can see what the issue is?
>> You are quite right; most of the methods that inline the accesses
>> don't call setPosition(). 
> I'm still confused here, what do you mean by "inline the accesses".
> Can you point to an example of what you mean?

I was refering to StoredPage and StoredRecordHeader which sometimes
access the page data as a byte array (what I called "inlined"), and
sometimes through ArrayInputStream. As the byte array is really a part
of StoredPage's internal state, I guess calling it "inlined" is not
very accurate.

> I was assuming that you meant there were many cases where code
> accessed the byte array directly and using ArrayInputStream, but I
> don't see many. ArrayInputStream.getData() is only called in three
> places, in FlushedScan and Scan. Maybe I misread what you are trying
> to say?

I'm sorry that I confused you. When I wrote that first comment, I had
been jumping back and forth between store and ArrayInputStream and
probably mixed the two since they contain some similar-looking code. I
thought I saw a pattern which I tried to describe, but I guess that
pattern only existed in my head (or at least it wasn't as common as I
initially felt it was).

The good news is that I find it much clearer and less confusing than I
did two days ago. Thanks to you all for helping me getting a clearer
picture of this part of the code!

And again, sorry for the confusion I have created for you guys.

Knut Anders - who will read the code more closely before calling it
confusing the next time :)

View raw message