PERF: Memoize core svgs in memory to avoid expensive XML parsing.

The XML parsing of SVGs is done whenever the cache expires or on the
first load after a reboot. In one of our production instance, parsing
ranges from 30ms to 70ms which is not ideal. Instead, we've decided to
make a small memory trade off here by memoizing the core SVGs once on
boot to avoid parsing of the SVG files during the duration of a request.
The memozied hash will take up 57440 bytes or 0.05744 megabytes in size.
This commit is contained in:
Alan Guo Xiang Tan
2021-06-01 14:57:24 +08:00
parent ab8949d13a
commit 0700e9382d
2 changed files with 67 additions and 23 deletions

View File

@ -914,9 +914,9 @@ module Discourse
schema_cache = ActiveRecord::Base.connection.schema_cache
# load up schema cache for all multisite assuming all dbs have
# an identical schema
RailsMultisite::ConnectionManagement.safe_each_connection do
# load up schema cache for all multisite assuming all dbs have
# an identical schema
dup_cache = schema_cache.dup
# this line is not really needed, but just in case the
# underlying implementation changes lets give it a shot
@ -948,6 +948,9 @@ module Discourse
},
Thread.new {
LetterAvatar.image_magick_version
},
Thread.new {
SvgSprite.core_svgs
}
].each(&:join)
ensure