From: mail@... Date: 2020-04-10T11:36:44+00:00 Subject: [ruby-core:97789] [Ruby master Feature#16773] Reduce allocations in net/http Issue #16773 has been reported by timcraft (Tim Craft). ---------------------------------------- Feature #16773: Reduce allocations in net/http https://bugs.ruby-lang.org/issues/16773 * Author: timcraft (Tim Craft) * Status: Open * Priority: Normal ---------------------------------------- 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) patch2.diff (742 Bytes) patch3.diff (1.07 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: