1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Halve memory allocation in S3Service#download

Aws::S3::Object#get returns a response with object content wrapped in an
in-memory StringIO object. StringIO#read will return a copy of the
content, which is not necessary because we can return the content
directly using StringIO#string. This halves memory allocation of
S3Service#download, because we remove unnecessary content duplication.
This commit is contained in:
Janko Marohnić 2018-04-23 21:29:55 +02:00
parent 80cbf19453
commit 19770d6ca3
No known key found for this signature in database
GPG key ID: 84166B4FB1C84F3E

View file

@ -33,7 +33,7 @@ module ActiveStorage
end
else
instrument :download, key: key do
object_for(key).get.body.read.force_encoding(Encoding::BINARY)
object_for(key).get.body.string.force_encoding(Encoding::BINARY)
end
end
end