Description
From prawnpdf/prawn#1246 (comment):
From the flamegraph it seems most of time (31.2% using Search
) is spent in Prawn::Images::PNG#split_image_data
and specifically in StringIO#read
and String#byteslice
called from there. The main cost is probably scanning the substring to compute the correct coderange (7-bit or valid for BINARY strings).
This should improve when TruffleRuby has adopted TruffleString (WIP).
It also indicates that in this case it might be better to compute the coderange lazily, since it's one of the rare cases where the coderange doesn't seem needed (for color.write data.read(color_bytes)
), cc @djoooooe.
From a wider perspective it's an unfortunate case of Ruby not having a real "byte array" structure, and String being a relatively poor fit for it.