- Have a dominant peer that is responsible for all data downloads. This eliminates the case of multiple threads fighting over download of the block chain and wasting time/bandwidth duplicating work.
- Make NetworkConnection an interface with two implementations: {TCP,Mock}NetworkConnection
- Rewrite the Peer/PeerGroup tests to use the mock connection. This simplifies testing of multiple independent peer threads within the same group.
- Switch off the MOBILE_OPTIMIZED mode as it's no longer required. It may still be useful for the multiplexing proxy project.
Cache checksum for non-empty messages.
VersionMessage and AddressMessage require some special handling. VersionMessage because it's never lazy parsed or cached. AddressMessage because when serializing PeerAddresses the time field is dynamic.
Checksum byte array is currently transient so no gains for a message extracted from java serialization then bitcoinSerialized. I don't think this would ever happen in real life but if it does then it could also be included in the serialized object.
Customize Sha256Hash.hashCode() method to only use first n bytes of the backing array. This provides uniqueness to 256^n combinations. As hashcode is not required to be guaranteed unique this fulfills the contract and reduces hashing time.
Use case is for applications that do a lot of mapping by Sha256Hash. Each put and get require several hashcode operations. Cached hashcode is already implemented in 8.patch.
Similar changes to this yielded huge performance benefits in poolserverj.
There is no point implementing a FastEquals version of equals given the bytes are essentially random and no byte is any more likely unique than another.
Add UnsafeByteArrayOutputStream. ByteArrayOutputStreams are used extensively and result in a lot of short lived byte arrays.
This patch contains two optimizations
1/ attempt to provide the final length to ByteArrayOutputStream constructor to avoid constantly resizing the backing array. Default size is 32 which means larger messages may require several array reallocations and almost all will require at least one.
2/ provides the UnsafeByteArrayOutputStream class which eliminates method synchronization. The toByteArray() will return the backing array rather than a copy if the correct length was provided in the constructor.
In the worst case scenario this cuts array allocations from 3 to 2.
In the most common worst case from 3 to 1.
In most best cases where final array size is greater than 128 bytes from > 4 to 1.