プロジェクト

全般

プロフィール

Feature #12788

Improve String lstrip and strip performance

Ary Borenszweig1日前に追加. 約14時間前に更新.

ステータス:
Closed
優先度:
Normal
担当者:
-
[ruby-core:77392]

説明

This adds a fast path for lstrip_offset in the case of single byte optimizable strings. This optimization already exists in rstrip_offset but I noticed it was missing in rstrip.

I made sure to only remove ascii space, not '\0', to preserve backwards compatibility. (rstrip seems to remove '\0', but not lstrip)

A benchmark:

s = " " * 10_000_000
time = Time.now
p s.lstrip
p s.strip
puts Time.now - time

s = " " * 100_000_000
time = Time.now
p s.lstrip
p s.strip
puts Time.now - time

Times before: 0.195159 and 1.918969
Times after: 0.013684 and 0.143966

So a bit more than 10x faster.

By the way, Akira Matsuda-san gave a really nice closing keynote in RubyConf Brasil yesterday that encouraged all of us to use Ruby and contribute to it, so here is my first patch :-)

string_lstrip_improvement.patch 表示 (685 Bytes) Ary Borenszweig, 2016/09/26 01:02

関係しているリビジョン

リビジョン 56250
Nobuyoshi Nakada約23時間前に追加

string.c: fast path of lstrip_offset

  • string.c (lstrip_offset): add a fast path in the case of single byte optimizable strings, as well as rstrip_offset. [Feature #12788]

履歴

#1 Nobuyoshi Nakada約23時間前に更新

  • ステータスOpen から Closed に変更

Applied in changeset r56250.


string.c: fast path of lstrip_offset

  • string.c (lstrip_offset): add a fast path in the case of single byte optimizable strings, as well as rstrip_offset. [Feature #12788]

#2 [ruby-core:77405] Ary Borenszweig約15時間前に更新

Thank you Nobu-san for reviewing and accepting this. Matsuda-san also mentioned a "patch monster" in his talk, I think now I know what he means :-)

#3 [ruby-core:77406] Akira Matsuda約14時間前に更新

Ary Borenszweig wrote:

Thank you Nobu-san for reviewing and accepting this. Matsuda-san also mentioned a "patch monster" in his talk, I think now I know what he means :-)

🤘🏻

他の形式にエクスポート: Atom PDF