creek
creek copied to clipboard
Reduce repeated calls to node name and type
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 |