Re: ClientPreparedQueryBindings setInt method convert int directly to byte array
Posted by: chen yi
Date: December 23, 2021 02:34AM

Hi Filipe Silva

Yes we exetend Calendar and implement a new Calendar that override clone method
solved the above problem.

we do above optimization that we sure that we use local timezone. thanks for your advise again.

could jdbc driver do the same optimization to reuse Calendar object avoid Calendar.clone?

another optimization is about BigDecimal

MysqlBinaryValueDecoder decode decimal that do following things.

public <T> T decodeDecimal(byte[] bytes, int offset, int length, ValueFactory<T> vf) {
BigDecimal d = new BigDecimal(StringUtils.toAsciiString(bytes, offset, length));
return vf.createFromBigDecimal(d);
}

in our code we do some optimization maybe useful.

static final ThreadLocal <char[]> CHARS = ThreadLocal.withInitial(() -> new char[32]);

public BigDecimal toBigDecimal (byte[] bytes) {
final int n = bytes.length; char[] c = n <= 32 ? CHARS.get() : new char[n];
for(int i = 0; i < n; i++) c = (char) bytes; return new BigDecimal(c, 0, n);
}

if you don't want to use ThreadLocal. new char[n] can also reduce String copy

we profiled above code's memory allocation and cpu usage.

memory allocation before : 19.31% after optimization : maybe 0% that can't find from profiler file.

cpu usage before : 8.73% after optimization : maybe 0% that can't find from profiler file.

this forums can't upload file so I create a github repo and upload related images and profiler files to repo
more details please visit https://github.com/leonchen83/mysql-driver/issues/1

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.