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

ruby-grape / grape-entity / 664 / 6
96%
master: 96%

Build:
DEFAULT BRANCH: master
Ran 15 Jul 2020 06:02PM UTC
Files 25
Run time 1min
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

15 Jul 2020 06:00PM UTC coverage: 95.851% (+0.03%) from 95.822%
2.4.10

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)

693 of 723 relevant lines covered (95.85%)

100.67 hits per line

Source Files on job 664.6 (2.4.10)
  • Tree
  • List 0
  • Changed 4
  • Source Changed 4
  • Coverage Changed 1
Coverage ∆ File Lines Relevant Covered Missed Hits/Line
  • Back to Build 651
  • Travis Job 664.6
  • 5d6b7120 on github
  • Prev Job for 2.4.10 on master (#658.6)
  • Next Job for 2.4.10 on master (#666.6)
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