There is a significant speed improvement if the value does not need to be escaped, as tag! escapes all values to ensure that valid XML is generated. For known binary values, it is at least an order of magnitude faster to Base64 encode binary values and directly put them in the output XML than to pass the original value or the Base64 encoded value to the tag! method. It definitely makes no sense to Base64 encode the value and then give it to tag!, since that just adds additional overhead.
# File activerecord/lib/active_record/serializers/xml_serializer.rb, line 299 def needs_encoding? ![ :binary, :date, :datetime, :boolean, :float, :integer ].include?(type) end