Skip to content

Utils::HeaderHash is EXTREMELY expensive #738

@schneems

Description

@schneems

Hypothetically if it was safe to remove HeaderHash usage right now, we would see

rack/lib x 7318
rack/lib x 5678

22.4 % fewer objects per request, and here's the kicker:

Speed with Header Hash

Calculating -------------------------------------
                 ips        51 i/100ms
-------------------------------------------------
                 ips      524.8 (±9.3%) i/s -       2601 in   5.005893s

Speed Without header Hash

Calculating -------------------------------------
                 ips        62 i/100ms
-------------------------------------------------
                 ips      649.2 (±8.8%) i/s -       3224 in   5.005930s

We get a (649.2 - 524.8 )/524.8 * 100 # => 23 % faster response only by removing HeaderHash. This is against a whole Rails app, not just Rack benchmarks in isolation. I don't know about you, but that sounds like a lot.

Reality

I know we can't remove HeaderHash wholesale, but we should do an audit of the places it's used, maybe it's not necessarry everywhere.

Perhaps we can cross reference documentation and for all classes that explicitly mention returning a header hash with this behavior (preserves original keys, and but allows for access with varying case), if documentation doesn't exist re-write to not use HeaderHash. Is that crazy? This util class is new to me, so I would appreciate any background info you might have.

With no changes or fixes, wholesale removing HeaderHash behavior from Rack causes 5 failures out of 2020 assertions in the test suite.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions