Project

General

Profile

Actions

Feature #17219

closed

Make URI#hostname 86-89% and hostname= 55-154% faster

Added by lzap (Lukas Zapletal) over 3 years ago. Updated about 3 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:100318]

Description

Hello,

URI#hostname extends URI#host with IPv6 support. In URI, IPv6 address must have square brackets (e.g. http://[2001:db8::1]), URI#hostname strips these characters out while URI#hostname= adds them if missing. There are three regular expressions to perform these tasks which can dramatically slow down performance. I am attaching a two-line patch and here is a benchmark: https://gist.github.com/lzap/24cbecb47daf29111350e41a24250922

Results are in the gist. A patch and a PR incoming.


Files

3635.patch (974 Bytes) 3635.patch Patch for URI#hostname(=) lzap (Lukas Zapletal), 10/07/2020 08:38 AM

Updated by lzap (Lukas Zapletal) over 3 years ago

There is a nil exception in the test suite with the initial patch. Also @nobu (Nobuyoshi Nakada) on Github pointed out that start_with? and end_with? might be faster which is indeed the case. I will update the patch shortly.

Updated by lzap (Lukas Zapletal) over 3 years ago

  • Subject changed from Make URI#hostname 18-20% and hostname= 31-156% faster to Make URI#hostname 86-89% and hostname= 55-154% faster
  • Description updated (diff)

So I learned that URI is a separate rubygem, therefore I filed PR against https://github.com/ruby/uri/pull/12 and this RM issue is no longer necessary I guess. Please close.

Actions #4

Updated by jeremyevans0 (Jeremy Evans) about 3 years ago

  • Status changed from Open to Closed
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0