Files
floci/src/main/java/io
TATSUNO “Taz” Yasuhiro 3dbbb46161 perf(s3): speed up in-memory PutObject, GetObject, DeleteObject and ListObjectsV2 (#7386)
* perf(s3): cut PutObject work in memory mode

A PutObject parsed the bucket's OwnershipControls XML twice and read a
1 KB body through a 64 KB buffer into a growing stream.

Bucket now caches the parsed ObjectOwnership until the XML changes. The
body is read into an array sized from the declared length, up to 64 MiB,
and larger or undeclared bodies keep the growing read. ETag hex uses
HexFormat, the event sequencer is written without String.format, and the
in-process dataGeneration token comes from a counter instead of
SecureRandom. S3Object and Part get copy constructors so a copy no longer
allocates collections it drops right away.

* perf(s3): list objects without per-key allocation

ListObjects filtered the object store through the account-aware wrapper,
which built the relative key of every stored entry, and the S3 predicate
rebuilt the null-version prefix for each one. The result was then
copied, sorted in full and filtered by the continuation token afterwards.
The handler asked UriInfo for the query map on each of its 25 subresource
checks and formatted LastModified with DateTimeFormatter.

AccountAwareStorageBackend gains scanRaw, which hands the stored key to
the filter, so ListObjects tests prefixes on it directly. Objects at or
before the continuation token are dropped before the sort, and common
prefixes at or before it are never collected. S3QueryParams reads the
query map once per request for the list, put, get, head and delete
handlers. The list handler formats seconds-precision timestamps itself
and presizes its XmlBuilder.

* perf(s3): serve in-memory GetObject bodies as byte arrays and trim DeleteObject

A GetObject in memory mode wrapped its byte array in a StreamingOutput,
which resteasy wrote through a blocking Vert.x output stream, formatted
Last-Modified with DateTimeFormatter, and resolved the bucket twice. A
DeleteObject entered RequestScopes.callAs even when the caller already
was the bucket owner, and swept the annotation store for every key.

ObjectRead carries the in-memory body, which the handler returns as the
entity with the same headers. Last-Modified is written by a small RFC 822
formatter that falls back to the DateTimeFormatter outside four-digit
years. The optimistic read reuses the bucket it resolved. DeleteObject
runs directly when the store's account is the owner's, and the annotation
sweep returns at once when no annotation exists.

* perf(s3): decode object keys and read query parameters only when needed

The object and list handlers decoded the raw path twice per request and
walked its segments even when no ".." could be present, re-wrapped the
query map for every trailer, tagging and checksum-mode lookup, lowercased
every request header while looking for user metadata, and resolved the
MD5 provider by reflection twice per PutObject.

URLDecoder runs only when the path carries a percent sign or a plus, and
the traversal check returns early without "..". The hot handlers reuse
their S3QueryParams for the trailer, tagging, checksum-mode and user
metadata lookups, user metadata matching lowercases only the x-amz-meta-
names, and MD5 digests are cloned from a prototype.

* perf(s3): hash an in-memory PutObject body once and trim the request helpers

The memory branch of PutObject now takes the ETag and the stored checksum
from the digesting stream, as the disk branch does, instead of hashing the
body again under the bucket lock. The controller parses the declared size
and resolves the trailer header once per request, skips the CloudTrail
event prologue when the account has no trail, reuses one formatted
LastModified for objects written in the same second, and checks a key for
traversal with a path only when it contains "..". XmlBuilder escapes into
its own buffer and appends numbers without a String.

S3QueryParams delegates its raw query check to S3RequestParser, which now
scans without splitting. The Digests helper hands out MD5 digests cloned
from a prototype, so S3Service, S3Object and DigestingInputStream share
it. Dead and single-use overloads in S3Controller and S3Service are gone,
Part.copyAll replaces two copies of the part list copy, ObjectRead carries
the body only once, Bucket derives the ownership flag in its setter, and
AccountAwareStorageBackend keeps its existing key concatenations.

* perf(s3): bound the query parameter name scan to its own segment

The search for "=" ran to the end of the query for every segment without
one, so a query of many valueless flags was scanned quadratically.

* docs(s3): describe where ObjectRead finds an in-memory body
2026-11-03 19:45:16 -04:00
..