Update parser.rb for ruby 3.4 warning#246
Conversation
There was a problem hiding this comment.
This change results in a copy of the underlying String data, whereas the original code merely changed the encoding (overwriting a few bytes in the String object data) without copying any of the bytes.
This degrades performance.
What was the warning that this commit is attempting to solve?
Thanks,
B.
|
Any here i the warning: /app/vendor/bundle/ruby/3.4.0/gems/combine_pdf-1.0.29/lib/combine_pdf/parser.rb:727: warning: string returned by :__WKANCHOR_4.to_s will be frozen in the future |
|
Thanks! Seems related to this: ...which indicates it might relate to a specific path (or the code Also, What do you think? B. |
|
Unfortunately I do not have the entire stack on sentry because i only send the first line in backtrace. If I reproduce this locally i can tell you which line led to this warning! I've seen a lot of |
chaadow
left a comment
There was a problem hiding this comment.
@boazsegev what do you think of this instead?
|
@boazsegev Happy new year! I've tested this (by using |
| dests_arry = (@names_object[:Dests] ||= {}) | ||
| dests_arry = ((dests_arry[:referenced_object] || dests_arry)[:Names] ||= []) | ||
| ((catalogs[:Dests][:referenced_object] || catalogs[:Dests])[:referenced_object] || (catalogs[:Dests][:referenced_object] || catalogs[:Dests])).each {|k,v| next if CombinePDF::PDF::PRIVATE_HASH_KEYS.include?(k); dests_arry << unify_string(k.to_s); dests_arry << v; } | ||
| ((catalogs[:Dests][:referenced_object] || catalogs[:Dests])[:referenced_object] || (catalogs[:Dests][:referenced_object] || catalogs[:Dests])).each {|k,v| next if CombinePDF::PDF::PRIVATE_HASH_KEYS.include?(k); dests_arry << unify_string(+(k.to_s)); dests_arry << v; } |
There was a problem hiding this comment.
I'm not a fan of the +, as it forces Ruby to duplicate the string and degrades performance.
Also, it seems a better approach might be to add a fix in unify_string rather than every time it's called.
I'll try to come up with a solution as well.
There was a problem hiding this comment.
I've seen the solution which is to duplicate if the string passed is frozen
but it won't work in a setting where all strings are considered frozen, ( i mean right now they are not, but they will be)
so your solution will probably work in the future, but right now it will still emit warnings :/
|
@boazsegev i know you've cut a release recently, so I've decided to use on production to check if it fixes all issues, but i still got some ruby warnings like here: /app/vendor/bundle/ruby/3.4.0/gems/combine_pdf-1.0.31/lib/combine_pdf/parser.rb:730: warning: string returned by :__WKANCHOR_6.to_s will be frozen in the futureor /app/vendor/bundle/ruby/3.4.0/gems/combine_pdf-1.0.31/lib/combine_pdf/parser.rb:730: warning: string returned by :__WKANCHOR_4.to_s will be frozen in the future |
No description provided.