google-cloud-php icon indicating copy to clipboard operation
google-cloud-php copied to clipboard

chore(Spanner): Make createTransactionSelector faster

Open saranshdhingra opened this issue 1 year ago • 2 comments

This PR simply replaces the use of decodeMessage from the Serializer and uses the mergeFromJsonString and the protobuf class's setter method.

The metrics on average are:

Using decodeMessage

When createTransactionSelector is called the first time: 900 us(micros) When createTransactionSelector is called the second time: 300 us (This is low because the Serializer caches a lot of things like proto descriptors etc).

Using mergeFromJsonString

When createTransactionSelector is called the first time: 200 us(micros) When createTransactionSelector is called the second time: 150 us

saranshdhingra avatar May 24 '24 11:05 saranshdhingra

Seems like protobuf's mergeFromString doesn't work with the following: {"begin": {"readWrite": []}} whereas it works with: {"begin": {"readWrite": {}}}.

For now, closing this PR.

saranshdhingra avatar May 30 '24 09:05 saranshdhingra

Seems like protobuf's mergeFromString doesn't work with the following: {"begin": {"readWrite": []}} whereas it works with: {"begin": {"readWrite": {}}}.

I have made sure that the JSON string uses {} for empty arrays by providing the JSON_FORCE_OBJECT flag, but the emulator tests are still failing. This will require further investigation.

bshaffer avatar Jun 13 '24 19:06 bshaffer