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

country_select method causing a ton of object allocation in views #226

Open
ykamin-booth opened this issue Mar 13, 2024 · 0 comments
Open

Comments

@ykamin-booth
Copy link

ykamin-booth commented Mar 13, 2024

I have recently been troubleshooting memory bloat in my app and discovered that views that included the country_select method in forms were causing high object allocation--significantly higher than when I just manually replaced the method with a large select tag.

Here's an example form (new devise registration) and how I use country_select

<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name),  html: { multipart: true, novalidate: false}) do |f| %>
  <%= f.error_notification %>
  <div class="form-group">
    <%= f.input :email,
        required: true,
        autofocus: false,
        hint: "This will also be your Username",
        input_html: { autocomplete: "email", class: "form-control-no-validations form-control form-control-lg" }%>
   </div>
   <div class="form-group">
    <%= f.input :name,
       required: true,
       input_html: {autocomplete: "name", class: "form-control-no-validations form-control form-control-lg" }%>
    </div>
    <p class="mb-2">Phone Number</p>
    <div class="form-group">
    <%= country_select(nil, "country_code", { selected: @country_code, include_blank: true, format: :with_country_code}, { class: 'custom-select', id: 'phone_country_codes', style: 'width: 30%;' } ) %>
...

The memory trace in Skylight shows the following when this page is loaded:
image

When I replace the method with a select tag like this:

<select class="custom-select" id="phone_country_codes" style="width: 30%;" name="country_code"><option value="" label=" "></option>
<option value="AS">+1 (American Samoa)</option>
<option value="AI">+1 (Anguilla)</option>
<option value="AG">+1 (Antigua and Barbuda)</option>
<option value="BS">+1 (Bahamas)</option>
<option value="BB">+1 (Barbados)</option>
<option value="BM">+1 (Bermuda)</option>
<option value="CA">+1 (Canada)</option>
<option value="KY">+1 (Cayman Islands)</option>
<option value="DM">+1 (Dominica)</option>
<option value="DO">+1 (Dominican Republic)</option>
<option value="GD">+1 (Grenada)</option>
<option value="GU">+1 (Guam)</option>
<option value="JM">+1 (Jamaica)</option>
...

I get avg. allocations on the order of 15,000.

Do you know what accounts for this? It happens whether or not I use the custom format and with country_select version 8 or 9.

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

No branches or pull requests

1 participant