Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache SVG icons in memory #8481

Merged
merged 1 commit into from
Jun 18, 2024
Merged

Cache SVG icons in memory #8481

merged 1 commit into from
Jun 18, 2024

Conversation

chosak
Copy link
Member

@chosak chosak commented Jun 17, 2024

Currently any use of the {% svg_icon %} template tag loads the SVG contents from disk. This commit modifies that behavior so that SVG icons are cached in memory, to avoid the need to load from file each time.

In our icon library icon files range from 220 bytes to 2.6 KB in size. The total size of all icons is 2.8 MB.

Closes internal https://github.local/CFGOV/platform/issues/3667.

How to test this PR

Everything should work the same, just slightly faster at the expense of slightly greater memory usage.

Locally, SKIP_DJANGO_MIGRATIONS=1 tox -e unittest takes 285s vs 291s for me on main, as an example of code that does a whole bunch of icon loads. On our production instances, we don't limit memory usage for mod_wsgi. Our prod servers are t3.2xlarge which have 32GB of RAM. By inspection each of our running Apache processes can consume ~1GB so an extra 2.8MB isn't significant.

Checklist

  • PR has an informative and human-readable title
  • Changes are limited to a single goal (no scope creep)
  • Code follows the standards laid out in the CFPB development guidelines

Currently any use of the {% svg_icon %} template tag loads the SVG
contents from disk. This commit modifies that behavior so that SVG icons
are cached in memory, to avoid the need to load from file each time.

In our icon library [0] icon files range from 220 bytes to 2.6 KB in
size. The total size of all icons is 2.8 MB.

[0] https://github.com/cfpb/design-system/tree/6b566bdb7ae2ce4c80a1cd05404bf3ea2e8fe6fa/packages/cfpb-icons/src/icons
@chosak chosak requested review from wpears and willbarton June 17, 2024 21:05
@chosak chosak added this pull request to the merge queue Jun 18, 2024
Merged via the queue into main with commit 2cab236 Jun 18, 2024
12 checks passed
@chosak chosak deleted the optimize/svg-icon branch June 18, 2024 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants