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

Improve performance of gathering the ClassCount metric #3386

Merged
merged 2 commits into from
Jan 23, 2024

Conversation

ivoanjo
Copy link
Member

@ivoanjo ivoanjo commented Jan 17, 2024

What does this PR do?

This PR tweaks the ClassCount.available? method to cache its result.

The result is expected to be always the same for a given Ruby VM, so we don't need to keep checking again and again.

Motivation:

While looking at our GitLab test deployments, I noticed that on this big app, calling ObjectSpace.count_objects does have some cost (because this method goes through the whole Ruby heap).

I then noticed we always call it twice in a row -- we call available? and then call value:

image

It's trivial to avoid this, so I decided to open this tiny PR.

Additional Notes:

N/A

How to test the change?

Existing test coverage is enough :)

For Datadog employees:

  • If this PR touches code that signs or publishes builds or packages, or handles
    credentials of any kind, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.

@ivoanjo ivoanjo requested a review from a team as a code owner January 17, 2024 09:49
@github-actions github-actions bot added the core Involves Datadog core libraries label Jan 17, 2024
@ivoanjo ivoanjo requested a review from a team January 18, 2024 08:53
@ivoanjo ivoanjo force-pushed the ivoanjo/optimize-class-count branch from 73a844c to 11b79f3 Compare January 19, 2024 17:18
@ivoanjo
Copy link
Member Author

ivoanjo commented Jan 19, 2024

Update: Rebased on top of current master to pull in #3387 and get a green CI again.

@ivoanjo
Copy link
Member Author

ivoanjo commented Jan 22, 2024

CI is broken... Unrelated to this PR... Again... Fix is in #3390, I'll rebase once it's in master...

@ivoanjo ivoanjo force-pushed the ivoanjo/optimize-class-count branch from 31dddb9 to 37eec47 Compare January 23, 2024 08:16
@codecov-commenter
Copy link

codecov-commenter commented Jan 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (57976d5) 98.25% compared to head (eb504fc) 98.25%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3386   +/-   ##
=======================================
  Coverage   98.25%   98.25%           
=======================================
  Files        1262     1262           
  Lines       73603    73603           
  Branches     3442     3443    +1     
=======================================
  Hits        72316    72316           
  Misses       1287     1287           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

ivoanjo and others added 2 commits January 23, 2024 09:26
**What does this PR do?**

This PR tweaks the `ClassCount.available?` method to cache its result.

The result is expected to be always the same for a given Ruby VM, so
we don't need to keep checking again and again.

**Motivation:**

While looking at our GitLab test deployments, I noticed that on this
big app, calling `ObjectSpace.count_objects` does have some cost
(because this method goes through the whole Ruby heap).

I then noticed we _always_ call it twice in a row -- we call
`available?` and then call `value`:

![image](https://github.com/DataDog/dd-trace-rb/assets/2785847/a6f9fc20-058a-4018-babc-95e93ccbe06d)

It's trivial to avoid this, so I decided to open this tiny PR.

**Additional Notes:**

N/A

**How to test the change?**

Existing test coverage is enough :)
@ivoanjo ivoanjo force-pushed the ivoanjo/optimize-class-count branch from 9da8507 to eb504fc Compare January 23, 2024 09:26
@ivoanjo
Copy link
Member Author

ivoanjo commented Jan 23, 2024

So it appears that we were missing a few gemfile updates, that our github action pushed into this PR. I've looked into them and they look good. Going ahead and merging this PR.

@ivoanjo ivoanjo merged commit 282efa1 into master Jan 23, 2024
218 checks passed
@ivoanjo ivoanjo deleted the ivoanjo/optimize-class-count branch January 23, 2024 10:54
@github-actions github-actions bot added this to the 1.20.0 milestone Jan 23, 2024
@TonyCTHsu TonyCTHsu mentioned this pull request Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Involves Datadog core libraries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants