Skip to content

Conversation

@ooooooo-q
Copy link

I used memory_profiler to check where rubyXL was using a lot of memory, and fixed it.

"@#{v[:accessor]}" generates two String objects, which can be expensive depending on the access frequency, so we memoized it.

Result

rubyXL 3.4.20 (with Ruby 3.1.0)

  • write file
    • Total allocated: 16.41 MB (335760 objects)
    • Total retained: 6.58 kB (128 objects)
  • read file
    • Total allocated: 24.26 MB (340069 objects)
    • Total retained: 6.23 kB (57 objects)

memoize "@#{v[:accessor]}"

  • write file
    • Total allocated: 14.06 MB (276927 objects)
    • Total retained: 23.97 kB (558 objects)
  • read file
    • Total allocated: 21.82 MB (279137 objects)
    • Total retained: 23.62 kB (487 objects)

@paddor
Copy link
Contributor

paddor commented Jan 29, 2025

I'm just curious, would an instance variable not work for memoizing? Why a class variable?

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