You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What does the class Google\Cloud\Spanner\Bytes make? It's an abstraction for bytes, but there's no reason to do it on a library side. Even more, it's not necessary in 99% of cases when we work with Spanner, because usually bytes in Spanner are UUID or some small size of bytes, not BLOBs. For BLOBs exist other tools and services.
So, what is happening behind that abstraction? Steps:
get base64 encoded bytes from Spanner
decode it to bytes in a class Google\Cloud\Spanner\ValueMapper::decodeValue
make from bytes a resource php://temp and after making a Stream class in a construction of Google\Cloud\Spanner\Bytes class by calling GuzzleHttp\Psr7\Utils::streamFor
use in 99% Google\Cloud\Spanner\Bytes for transforming bytes to base64
base64 -> bytes -> resource -> stream -> base64 (if you don't store BLOBs in Spanner)
Saṃsāra...
So, what about memory consumption? UUID is 16 bytes but by all this abstraction, for every UUID, we pay about 100 times more memory(I've double-checked). Without that abstraction, there wouldn't be any extra memory allocations. And also CPU cycles are important.
What I propose: make that abstraction optional in the next major release, and make a mapper configurable in the current version.
Maybe you have a better option or idea of how to remove unnecessary abstraction.
The text was updated successfully, but these errors were encountered:
asamats
changed the title
Remove unnecessary abstraction of bytes type or give a choice to skip that abstraction
Remove unnecessary abstraction of bytes type or give an option to skip that abstraction
May 12, 2024
What does the class
Google\Cloud\Spanner\Bytes
make? It's an abstraction for bytes, but there's no reason to do it on a library side. Even more, it's not necessary in 99% of cases when we work with Spanner, because usually bytes in Spanner are UUID or some small size of bytes, not BLOBs. For BLOBs exist other tools and services.So, what is happening behind that abstraction? Steps:
Google\Cloud\Spanner\ValueMapper::decodeValue
php://temp
and after making a Stream class in a construction ofGoogle\Cloud\Spanner\Bytes
class by callingGuzzleHttp\Psr7\Utils::streamFor
Google\Cloud\Spanner\Bytes
for transforming bytes to base64base64 -> bytes -> resource -> stream -> base64 (if you don't store BLOBs in Spanner)
Saṃsāra...
So, what about memory consumption? UUID is 16 bytes but by all this abstraction, for every UUID, we pay about 100 times more memory(I've double-checked). Without that abstraction, there wouldn't be any extra memory allocations. And also CPU cycles are important.
What I propose: make that abstraction optional in the next major release, and make a mapper configurable in the current version.
Maybe you have a better option or idea of how to remove unnecessary abstraction.
The text was updated successfully, but these errors were encountered: