aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/lib
diff options
context:
space:
mode:
authorJanko Marohnić <janko.marohnic@gmail.com>2018-04-23 21:29:55 +0200
committerJanko Marohnić <janko.marohnic@gmail.com>2018-04-23 21:29:55 +0200
commit19770d6ca3ab72f760da47b5be484f36ae003f01 (patch)
treed4c4223ba7b6ad489021c9e67f6d1e532ad0fda6 /activestorage/lib
parent80cbf19453bb3fe22e8d038a9631b8436320788b (diff)
downloadrails-19770d6ca3ab72f760da47b5be484f36ae003f01.tar.gz
rails-19770d6ca3ab72f760da47b5be484f36ae003f01.tar.bz2
rails-19770d6ca3ab72f760da47b5be484f36ae003f01.zip
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.
Diffstat (limited to 'activestorage/lib')
-rw-r--r--activestorage/lib/active_storage/service/s3_service.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/activestorage/lib/active_storage/service/s3_service.rb b/activestorage/lib/active_storage/service/s3_service.rb
index 5e489f4be1..0286e7ff21 100644
--- a/activestorage/lib/active_storage/service/s3_service.rb
+++ b/activestorage/lib/active_storage/service/s3_service.rb
@@ -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