From 9c20014a8571680c37655be5ace2741d339631d5 Mon Sep 17 00:00:00 2001 From: Shawn Neal Date: Mon, 23 Jun 2014 19:17:37 -0700 Subject: [PATCH] Improved box checksum verification performance When adding large boxes verifying the checksum took noticably longer than expected because the Ruby GC was needlessly working overtime. --- lib/vagrant/util/file_checksum.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/vagrant/util/file_checksum.rb b/lib/vagrant/util/file_checksum.rb index 6a488d43b..0591603e7 100644 --- a/lib/vagrant/util/file_checksum.rb +++ b/lib/vagrant/util/file_checksum.rb @@ -8,7 +8,7 @@ class DigestClass end class FileChecksum - BUFFER_SIZE = 16328 + BUFFER_SIZE = 1024 * 8 # Initializes an object to calculate the checksum of a file. The given # ``digest_klass`` should implement the ``DigestClass`` interface. Note @@ -25,11 +25,12 @@ class FileChecksum # @return [String] def checksum digest = @digest_klass.new + buf = '' File.open(@path, "rb") do |f| while !f.eof begin - buf = f.readpartial(BUFFER_SIZE) + f.readpartial(BUFFER_SIZE, buf) digest.update(buf) rescue EOFError # Although we check for EOF earlier, this seems to happen