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

Enable frozen string literals #172

Merged

Conversation

tagliala
Copy link
Contributor

@tagliala tagliala commented Oct 14, 2024

@@ -60,20 +62,20 @@
context 'IO object' do
let(:answer) { 'read' }
let(:rio) { StringIO.new(answer, 'r') }
let(:wio) { StringIO.new('write', 'w') }
let(:wio) { StringIO.new(+'write', 'w') }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is the only noticeable change in this PR. I've searched for potential issues like << " or = '' but I couldn't find them

@tagliala tagliala force-pushed the chore/frozen-string-literal branch from e091800 to fb92137 Compare November 12, 2024 08:58
@tagliala tagliala force-pushed the chore/frozen-string-literal branch 2 times, most recently from 96d62fc to b25a180 Compare November 22, 2024 10:07
@tagliala
Copy link
Contributor Author

Hi @jamesmartin, sorry for the ping

if you can take a look at

Then we can go for this one. I'm also working on profiling and benchmarks

@jamesmartin
Copy link
Owner

@tagliala thanks for the ping. I've reviewed, approved and merged the three PRs on which this branch depends. Feel free to push this one forward whenever you have time. 👍

Additionally, tested locally with

```
RUBYOPT="--enable-frozen-string-literal --debug-frozen-string-literal" bundle exec rspec
```
@tagliala tagliala force-pushed the chore/frozen-string-literal branch 2 times, most recently from d422422 to 792e372 Compare November 29, 2024 08:26
@tagliala
Copy link
Contributor Author

@jamesmartin thanks, pushed

I cannot guarante 100% that there isn't an edge case which breaks with frozen string literals, but at the moment I didn't find one.

Here there are some comparisons on memory side. I don't know if this makes a difference when a page contains a single inline_svg_tag

Bench

def run_benchmark_sample(iterations: 1)
  # Plain
  HELPER.inline_svg_tag 'example.svg'

  # Class
  HELPER.inline_svg_tag 'example.svg', class: 'test-class'

  # Id
  HELPER.inline_svg_tag 'example.svg', id: 'test-id'

  # Aria
  HELPER.inline_svg_tag 'example.svg', title: 'Title', desc: 'Description', aria: true

  # Style
  HELPER.inline_svg_tag 'example.svg', style: 'margin: 0;'

  # ...
  HELPER.inline_svg_tag 'example.svg', class: 'test-class',
                                       id: 'test-id',
                                       style: 'margin: 0;',
                                       title: 'Title', desc: 'Description', aria: true

  # Different SVG
  HELPER.inline_svg_tag 'static_assets/assets0/some-document.svg', class: 'test-class'
end

Memory

Before

$ ./benchmarks/profile_memory.rb 
Total allocated: 43984 bytes (451 objects)
Total retained:  240 bytes (6 objects)

allocated memory by gem
-----------------------------------
     43984  inline_svg/lib

allocated memory by file
-----------------------------------
     31224  ./lib/inline_svg/transform_pipeline/transformations.rb
      4680  ./lib/inline_svg/transform_pipeline/transformations/transformation.rb
      2080  ./lib/inline_svg/id_generator.rb
      1960  ./lib/inline_svg/transform_pipeline.rb
      1680  ./lib/inline_svg/transform_pipeline/transformations/aria_attributes.rb
       840  ./lib/inline_svg/transform_pipeline/transformations/class_attribute.rb
       480  ./lib/inline_svg/transform_pipeline/transformations/style_attribute.rb
       400  ./lib/inline_svg/transform_pipeline/transformations/description.rb
       400  ./lib/inline_svg/transform_pipeline/transformations/title.rb
       160  ./lib/inline_svg/action_view/helpers.rb
        80  ./lib/inline_svg/transform_pipeline/transformations/id_attribute.rb

After

$ ./benchmarks/profile_memory.rb 
Total allocated: 39984 bytes (351 objects)
Total retained:  80 bytes (2 objects)

allocated memory by gem
-----------------------------------
     39984  inline_svg/lib

allocated memory by file
-----------------------------------
     31224  ./lib/inline_svg/transform_pipeline/transformations.rb
      3120  ./lib/inline_svg/transform_pipeline/transformations/transformation.rb
      1960  ./lib/inline_svg/transform_pipeline.rb
      1920  ./lib/inline_svg/id_generator.rb
       720  ./lib/inline_svg/transform_pipeline/transformations/aria_attributes.rb
       240  ./lib/inline_svg/transform_pipeline/transformations/class_attribute.rb
       240  ./lib/inline_svg/transform_pipeline/transformations/description.rb
       240  ./lib/inline_svg/transform_pipeline/transformations/title.rb
       160  ./lib/inline_svg/action_view/helpers.rb
       160  ./lib/inline_svg/transform_pipeline/transformations/style_attribute.rb

@tagliala tagliala marked this pull request as ready for review November 29, 2024 08:44
Copy link
Owner

@jamesmartin jamesmartin left a comment

Choose a reason for hiding this comment

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

@tagliala thanks for the PR and for the benchmarks. ✨

I cannot guarante 100% that there isn't an edge case which breaks with frozen string literals, but at the moment I didn't find one.

Let's trust the test suite and move forward from here. 👍

@jamesmartin jamesmartin merged commit 2d8c66c into jamesmartin:master Dec 2, 2024
7 checks passed
@tagliala tagliala deleted the chore/frozen-string-literal branch December 3, 2024 00:04
tagliala added a commit to tagliala/inline_svg that referenced this pull request Jan 7, 2025
This change qualifies for an entry in the changelog.

Additionally, removes some double whitespaces

Ref: jamesmartin#172
tagliala added a commit to tagliala/inline_svg that referenced this pull request Feb 3, 2025
This change qualifies for an entry in the changelog.

Additionally, removes some double whitespaces

Ref: jamesmartin#172
tagliala added a commit to tagliala/inline_svg that referenced this pull request Feb 3, 2025
This change qualifies for an entry in the changelog.

Ref: jamesmartin#172
tagliala added a commit to tagliala/inline_svg that referenced this pull request Feb 3, 2025
This change qualifies for an entry in the changelog.

Additionally:
- Fix some double spaces
- Fix link to 1.10.0 release

Ref: jamesmartin#172
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