• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ruby-grape / grape-entity / 664
96%

Build:
DEFAULT BRANCH: master
Ran 15 Jul 2020 06:01PM UTC
Jobs 6
Files 25
Run time 5min
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

pending completion
664

push

travis-ci

web-flow
pass options to delegators when they accept it (#336)

This change reduces hash allocations.

Here is a simplified example what was happening.

    def do_not_accept_keywords(**)
    end

    100.times { do_not_accept_keywords(hash: true) }

After measuring via memory profiler, we got this:

    Total allocated: 69600 bytes (300 objects)

    allocated memory by location
    -----------------------------------
         69600  profile/sample.rb:15

It points to a line where the method gets called. So, every call created a separate hash. It was
happening for `Grape::Entity::Delegator::PlainObject`.

If options get extracted, the picture is better.

    def do_not_accept_keywords(**)
    end

    opts = { hash: true }

    100.times { do_not_accept_keywords(opts) }

Allocation:

    Total allocated: 46632 bytes (201 objects)

    allocated memory by location
    -----------------------------------
         46400  profile/sample.rb:15
           232  profile/sample.rb:13

However, there is no object allocation if nothing is passed to the method.
options.

    Total allocated: 0 bytes (0 objects)

Btw, if a method "swallows" arguments, but nothing is passed, there is still allocation.

    def do_not_accept_keywords(**)
    end

    100.times { do_not_accept_keywords }

Result:

    Total allocated: 23200 bytes (100 objects)

    allocated memory by location
    -----------------------------------
         23200  profile/sample.rb:15

The splat operator brings its cost.

So, now Grape Entity checks whether the delegetor accepts options before passing them.

I measured this change against our production:

**Before:**

    Total allocated: 1512362 bytes (12328 objects)

    allocated memory by location
    -----------------------------------
         605520  /usr/local/bundle/gems/grape-entity-0.8.0/lib/grape_entity/entity.rb:537

**After:**

    Total allocated: 908402 bytes (9733 obj... (continued)

9 of 9 new or added lines in 4 files covered. (100.0%)

678 of 707 relevant lines covered (95.9%)

593.36 hits per line

Jobs
ID Job ID Ran Files Coverage
1 664.1 (2.5.8) 15 Jul 2020 06:01PM UTC 0
95.84
Travis Job 664.1
2 664.2 (2.6.6) 15 Jul 2020 06:01PM UTC 0
95.83
Travis Job 664.2
3 664.3 (2.7.1) 15 Jul 2020 06:01PM UTC 0
95.83
Travis Job 664.3
4 664.4 (ruby-head) 15 Jul 2020 06:01PM UTC 0
92.92
Travis Job 664.4
5 664.5 (jruby-head) 15 Jul 2020 06:04PM UTC 0
94.74
Travis Job 664.5
6 664.6 (2.4.10) 15 Jul 2020 06:02PM UTC 0
95.85
Travis Job 664.6
Source Files on build 664
Detailed source file information is not available for this build.
  • Back to Repo
  • Travis Build #664
  • 5d6b7120 on github
  • Prev Build on master (#658)
  • Next Build on master (#666)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc