Skip to content

Slightly reduce RAM usage#7301

Merged
Gargron merged 6 commits intomasterfrom
fix-mem-optimize
May 2, 2018
Merged

Slightly reduce RAM usage#7301
Gargron merged 6 commits intomasterfrom
fix-mem-optimize

Conversation

@Gargron
Copy link
Copy Markdown
Member

@Gargron Gargron commented May 1, 2018

  • Add derailed_benchmarks gem for performance benchmarking
  • Clean up requires throughout code (no performance change, but sidekiq plugins get required via the Gemfile, so manual require in each worker file has no effect)
  • Benchmark showed high number of allocations from ruby-oembed gem. Reimplemented using own service class.
  • Do not require TTY gems from Gemfile, require them from rake task. Reduced RAM of non-rake processes by a very small amount.
Type Before After
At boot time 102.9414 - 108.4727 MiB 97.4727 - 103.6758 MiB
During request 87.0625 - 88.375 MiB 84.9531 - 85.1484 MiB

Replaced preloaded JSON-LD contexts (stored as Ruby classes) with a method that hooks into the JSON-LD document loader and caches the response of the context using Rails cache.

Benefits:

  • This reduces the boot time RAM by a further ~6 MiB
  • Loads any JSON-LD context using our own code and timeouts and caches it for quick retrieval
  • Technically the memory requirements are the same, but those ~6 MiB are in Redis and only retrieved when needed, and can be garbage-collected after
  • Supports changing contexts better than hardcoding them

Other unfixed high-memory offenders:

@Gargron Gargron added the performance Runtime performance label May 1, 2018
@Gargron Gargron force-pushed the fix-mem-optimize branch 2 times, most recently from d40ef11 to aa83f91 Compare May 1, 2018 22:22
@Gargron
Copy link
Copy Markdown
Member Author

Gargron commented May 1, 2018

@nullkal Can anything be done about Charlock Holmes? Is it absolutely necessary? 3 MiB are not too much if there is no way around it, but I want to check.

@Gargron Gargron force-pushed the fix-mem-optimize branch from aa83f91 to de82af7 Compare May 1, 2018 22:36
Copy link
Copy Markdown
Member

@nightpool nightpool left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+r when tests pass, but we should make sure to keep an eye on the OEmbed stuff during the RC cycle in case this introduces regressions.

@Gargron Gargron force-pushed the fix-mem-optimize branch from 3f5e840 to 3603c71 Compare May 2, 2018 16:49
@Gargron Gargron merged commit cb5b5cb into master May 2, 2018
@Gargron Gargron deleted the fix-mem-optimize branch May 2, 2018 16:58
@nschonni nschonni mentioned this pull request Feb 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Runtime performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants