Project

General

Profile

Feature #16773

Reduce allocations in net/http

Added by timcraft (Tim Craft) 3 months ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:97789]

Description

Some minor patches which help to reduce allocations in net/http, which should benefit any programs making heavy use of net/http:

  • patch1.diff sets frozen_string_literal to true for some net/http files (I used ''.dup for mutable strings to match existing code)

  • patch2.diff uses (frozen) strings instead of regexps for split separator arguments in lib/net/http/header.rb

  • patch3.diff eliminates some calls to self[] in lib/net/http/header.rb which eliminates some unnecessary downcasing and string allocations

With these patches applied I get a modest but significant reduction in allocations using a test script which performs 10 HTTP requests representative of the workload for my use case (using net/http inside a web application). Before (recent master):

Total allocated: 3.21 MB (34031 objects)

After (with patches applied):

Total allocated: 2.99 MB (28756 objects)

I have run make test-all TESTS=net/http and all tests still pass.


Files

patch1.diff (1.75 KB) patch1.diff timcraft (Tim Craft), 04/10/2020 11:35 AM
patch2.diff (742 Bytes) patch2.diff timcraft (Tim Craft), 04/10/2020 11:35 AM
patch3.diff (1.07 KB) patch3.diff timcraft (Tim Craft), 04/10/2020 11:35 AM

No data to display

Also available in: Atom PDF