Skip to content

Conversation

@pocke
Copy link
Member

@pocke pocke commented Aug 6, 2024

This patch dedups empty arrays allocated during parsing.

Currently, RBS allocates many arrays during parsing. It consumes a lot of memory.

This patch reduces memory usage by deduping empty arrays.

BTW, I'm also working on deduping empty Hashes. It caused a performance problem. Therefore this PR focuses on Array and I'll make another PR for Hash.

Profiling

I've checked the memory usage by benchmark/memory_new_rails_env.rb script.

before:

Total allocated: 158965078 bytes (1615620 objects)
Total retained:  56607852 bytes (566708 objects)

(snip)

allocated memory by class
-----------------------------------
  81452592  Hash
  20455584  Array
  20114192  RBS::Location
  13382510  String

after:

Total allocated: 153021766 bytes (1466984 objects)
Total retained:  52321620 bytes (459558 objects)

(snip)

allocated memory by class
-----------------------------------
  81456912  Hash
  20114856  RBS::Location
  14508496  Array
  13380142  String

It reduced ~8% retained memory.

I've confirmed steep check works well with this patch.

@pocke pocke force-pushed the dedup-empty-arrays-and-hashes branch from 883d9e4 to c6564dd Compare August 8, 2024 06:54
@pocke pocke changed the title Dedup empty arrays and hashes Dedup empty arrays Aug 20, 2024
@pocke pocke changed the title Dedup empty arrays Dedup empty arrays in parsing Aug 20, 2024
@pocke pocke force-pushed the dedup-empty-arrays-and-hashes branch from 2c356c0 to 4fa8c82 Compare September 2, 2024 08:34
Copy link
Member

@soutaro soutaro left a comment

Choose a reason for hiding this comment

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

👍

@pocke pocke added this pull request to the merge queue Sep 3, 2024
Merged via the queue into ruby:master with commit c3e8299 Sep 3, 2024
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