Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary abstraction of bytes type or give an option to skip that abstraction #7305

Open
asamats opened this issue May 12, 2024 · 1 comment

Comments

@asamats
Copy link

asamats commented 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:

  • 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.

@asamats 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
@ser-sergeev
Copy link

    public function __construct($value)
    {
        $this->value = Utils::streamFor($value);
    }

remove this $this->value = Utils::streamFor($value);

and it will be significantly much better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants