Skip to content

Reduce repeated calls to node name and type #131

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

transoceanic2000
Copy link

Initial attempt to help with #122

In the main loop we may call node.name and node.node_type several times in different if statement. node.name in particular results in allocation of a string, boosting memory usage. Calling them once and storing them locally reduces memory use.

In a test reading 10k (mostly empty) rows from a spreadsheet can see that the extra allocations from calling node.name in later branches of the if disappear from the stats. Overall %age reduction in allocations is small (~2% in this case), so won't fix the memory usage but will help. %age reduction may be larger for sheets that contain more cells, as the later branches will be exercised more often.

sourcefile sourceline class count comments
gems/nokogiri-1.18.2-arm64-darwin/lib/nokogiri/xml/reader.rb 127 String 64407
gems/rubyzip-2.4.1/lib/zip/inflater.rb 19 String 42986
gems/nokogiri-1.18.2-arm64-darwin/lib/nokogiri/xml/reader.rb 127 Hash 33405
gems/rubyzip-2.4.1/lib/zip/ioextras/abstract_input_stream.rb 20 String 28666
gems/rubyzip-2.4.1/lib/zip/inflater.rb 19 Range 14330
creek/lib/creek/sheet.rb 122 String 11565 remains the same
creek/lib/creek/sheet.rb 110 Hash 11565
creek/lib/creek/sheet.rb 125 Hash 10001
creek/lib/creek/sheet.rb 124 Hash 10001
creek/lib/creek/sheet.rb 127 String 1564 removed
creek/lib/creek/sheet.rb 145 String 1562 removed
creek/lib/creek/sheet.rb 141 String 1537 removed
creek/lib/creek/sheet.rb 148 String 706

In the main loop we may call node.name and node.node_type several times. node.name in particular results in allocation of a string, boosting memory usage. Calling them once and storing them locally will reduce memory use.
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.

1 participant