Skip to content
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

Reduce object allocation while compiling #2496

Merged
merged 8 commits into from
Sep 8, 2024

Conversation

ericproulx
Copy link
Contributor

@ericproulx ericproulx commented Sep 8, 2024

This PR reduces object allocation when compiling an api.

The function prepare_path was calling inheritable_setting.to_hash 2 times to just keep namespace_stackable and namespace_inheritable.

Current allocation / bytes

Total allocated: 62277446 bytes (334535 objects)
Total retained:  5954533 bytes (15516 objects)

Current allocation / types

allocated objects by class
-----------------------------------
    218676  Array
     89913  Hash

This PR allocation/bytes

Total allocated: 51007518 bytes (220812 objects)
Total retained:  5954325 bytes (15514 objects)

This PR allocation/types

allocated objects by class
-----------------------------------
    128512  Array
     66354  Hash

This PR also changes the following

  • use include instead of .send(:include)
  • create a helpers module only if a helper is defined otherwise it's nil
  • Remove || {} in favor of handling nil cases in some options passed to middlewares.

@ericproulx ericproulx marked this pull request as ready for review September 8, 2024 15:37
@ericproulx ericproulx requested a review from dblock September 8, 2024 15:37
@ericproulx ericproulx changed the title Reduce hash allocation Reduce object allocations while compiling Sep 8, 2024
@ericproulx ericproulx changed the title Reduce object allocations while compiling Reduce object allocation while compiling Sep 8, 2024
Object allocation instead of just hash
@dblock dblock merged commit 2d94dd8 into ruby-grape:master Sep 8, 2024
56 checks passed
@numbata
Copy link
Contributor

numbata commented Sep 11, 2024

Fantastic job 👍

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.

3 participants