Repository navigation
Allocate shape metadata on first write (3,800 fewer empty Hashes when loading S3 and KMS) - #3491
Conversation
1fb151f to
6ff8394
Compare
|
I rebased this onto |
|
Re-reading this I found that shape metadata isn't only written while the API loads: the rest-xml response stubbing also writes it at request time. It always writes the same key and value, so a concurrent first write on the lazy Hash can't lose anything; I added a sentence about it to the description. |
jnunn-aws
left a comment
There was a problem hiding this comment.
Reproduced on Ruby 4.0.9. Loading S3 and KMS leaves 3,833 fewer empty Hashes and 0.61 MB less memsize_of_all (about 0.15 MB on Ruby 3.2, where an empty Hash is 40 bytes, not 160). S3 and KMS metadata reads are unchanged, and 32 threads making the first stubbed get_bucket_policy_status call get the same result.
6ff8394 to
09b0ed5
Compare
|
Thanks @jnunn-aws for checking it down to Ruby 3.2 and the threaded first call! The CHANGELOG conflicted again once 3.268.0 shipped, so I rebased onto |
Every Shape and ShapeRef created an empty metadata Hash, though most never get any metadata. Loading the S3 and KMS APIs left 3,833 of them, about 0.6 MB of Ruby objects. Create the Hash on the first []= instead; [] reads nil as no metadata. Assisted-by: Claude Opus 5.5 [Claude Code]
09b0ed5 to
ad7d7dd
Compare
Every
Seahorse::Model::Shapes::ShapeandShapeRefcreates an empty metadata Hash ininitialize, though most of them never get any metadata. This creates it on the first[]=instead, and[]reads a missing Hash as no metadata. It's a small one, next to #3465: about 0.6 MB less per process for S3 and KMS, and the same for every other service API an app loads.Loading the S3 and KMS APIs (
ClientApi::API), onversion-3at 1419898 and with this change, Ruby 4.0.9:version-3ObjectSpace.memsize_of_allLoad time doesn't change (within noise, interpreter and YJIT). Query-protocol responses (STS, SQS, SNS, IAM) also allocate 3 Hashes less each, since
Query::Handler#rulesbuilds a shape and two refs per response.Every metadata read on the S3 and KMS models (4,273 shape, ref and operation reads over 27 keys, including one that is never set) gives the same values before and after.
aws-sdk-core(2,496 examples) andaws-sdk-s3(1,721) specs pass, and the new spec covers reading metadata that was never set. Metadata is written while the API loads; the only later writer is the rest-xml response stubbing, which always writes the same key and value, so a concurrent first write can't lose anything.OperationandApikeep their eager Hash: there are only a few of them, so changing them would grow the diff for no measurable gain.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
AI-assisted; prompted, reviewed and verified by me.