While investigating #117, #127, and #134, I noticed that the #default_proc usage in MIME::Types::Container could potentially cause uncontrolled growth in memory by the constant querying of unknown types and/or extensions.
MIME::Types::Container was originally a subclass of Hash with a default Proc (->(h, k) { h[k] = Set.new }) and some methods to assist with JSON/YAML encoding and Marshal support (because the presence of the default_proc breaks those things or is missing on restoration).
This particular implementation is extremely useful during construction, because it allowed for the simplification of a number of call-sites, but it had the unintended consequence of recording every missed query and adding an empty (but mutable) Set during normal (and much more frequent) execution.
While investigating #117, #127, and #134, I noticed that the
#default_proc
usage inMIME::Types::Container
could potentially cause uncontrolled growth in memory by the constant querying of unknown types and/or extensions.MIME::Types::Container
was originally a subclass ofHash
with a defaultProc
(->(h, k) { h[k] = Set.new }
) and some methods to assist with JSON/YAML encoding and Marshal support (because the presence of thedefault_proc
breaks those things or is missing on restoration).This particular implementation is extremely useful during construction, because it allowed for the simplification of a number of call-sites, but it had the unintended consequence of recording every missed query and adding an empty (but mutable) Set during normal (and much more frequent) execution.