Skip to content

[PLT-341] Reduce memory footprint - #42

Merged
bapu-nexl merged 4 commits into
mainfrom
PLT-341-2
Mar 4, 2026
Merged

bapu-nexl merged 4 commits into
mainfrom
PLT-341-2

Conversation

@bapu-nexl

@bapu-nexl bapu-nexl commented Mar 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Reduce memory footprint for initialize method PublicDomainSuffix

Checklist

  • Changelog updated
  • Version bumped in rails_values.gemspec

Test plan

No change in behaviour tests already present

TOP_LEVEL_DOMAINS_SET = Set.new(TOP_LEVEL_DOMAINS).freeze

def initialize(content)
matching_tld = TOP_LEVEL_DOMAINS.any? { |d| content.upcase.split('.').last == d }

@bapu-nexl bapu-nexl Mar 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Probably not the main issue behind the OOM crashes we are having but still has a big memory footprint because of content.upcase.split('.').last returning new strings in the loop

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to reduce per-call allocations/memory usage in RailsValues::PublicDomainSuffix#initialize, and includes a gem version bump consistent with the release.

Changes:

  • Bump gem version from 2.0.8 to 2.0.9.
  • Optimize TLD validation in PublicDomainSuffix#initialize by precomputing the last domain part once and using a Set for membership checks.
  • Reduce allocations in EmailAddressList#to_s by joining the list directly (avoiding an intermediate map(&:to_s) array).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
rails_values.gemspec Bumps gem version to 2.0.9.
lib/rails_values/public_domain_suffix.rb Introduces a Set for faster/leaner TLD membership checks during initialization.
lib/rails_values/email_address_list.rb Simplifies to_s to avoid creating a temporary array of strings.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +18 to +19
TOP_LEVEL_DOMAINS_SET = Set.new(TOP_LEVEL_DOMAINS).freeze

Copilot AI Mar 4, 2026

Copy link

Choose a reason for hiding this comment

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

Set is referenced here but this file doesn’t require the Ruby stdlib set. In environments where Set hasn’t already been loaded, this will raise NameError: uninitialized constant Set. Add require 'set' near the top of the file (or ensure it’s required before this class is loaded).

Copilot uses AI. Check for mistakes.

@grantspeelman grantspeelman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks Good 👍🏽

@bapu-nexl bapu-nexl changed the title Reduce memory footprint [PLT-341] Reduce memory footprint Mar 4, 2026
@bapu-nexl
bapu-nexl merged commit d9874f8 into main Mar 4, 2026
9 checks passed
@bapu-nexl
bapu-nexl deleted the PLT-341-2 branch March 4, 2026 09:34
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.

3 participants