Ruby 3.2.0 把 YJIT 列為穩定功能了

去年有寫過 RubyYJIT 帶來的效能提昇:「YJIT 帶給 Ruby 大量的效能提昇」。

在這次的 Ruby 3.2.0 發布就把 YJIT 列為穩定功能了:「Ruby 3.2.0」。

  • YJIT is no longer experimental
    • Has been tested on production workloads for over a year and proven to be quite stable.

另外就是支援的平台,看起來是多了 arm64 這邊的支援,所以馬上列表就多了一堆新機器:

  • YJIT now supports both x86-64 and arm64/aarch64 CPUs on Linux, MacOS, BSD and other UNIX platforms.
    • This release brings support for Apple M1/M2, AWS Graviton, Raspberry Pi 4 and more.

另外是每個程式語言幾乎都會遇到的 regexp 類的問題,這次 Ruby 3.2.0 利用 Memoization 的方式降低某些 regexp 的消耗:

# This match takes 10 sec. in Ruby 3.1, and 0.003 sec. in Ruby 3.2
/^a*b?a*$/ =~ "a" * 50000 + "x"

而另外一組 regexp 也可以看出類似的效果:

用一些記憶體空間換取效能,降低被 DoS 的一些機會。另外一方面,引入了 regexp timeout 的 workaround,緩解真的被打的時候的資源消耗上限:

The optimization above cannot be applied to some kind of regular expressions, such as those including advanced features (e.g., back-references or look-around), or with a huge fixed number of repetitions. As a fallback measure, a timeout feature for Regexp matches is also introduced.

Regular Expression 版本的填字遊戲

Update:被朋友提醒在 2014 年的時候寫過了:「Regular Expression 字謎遊戲...」。

Hacker News Daily 上看到的填字遊戲,跟一般的填字遊戲不同的是,他的靠 Regular expression 表達規則:「RegEx Crossword」。

Hacker News 上面的討論有教你怎麼算,不過建議先自己玩看看:「RegEx Crossword (jimbly.github.io)」。

之前就有印象有看過,但用 Hacker News 上的搜尋引擎只翻到這次。跑到 GitHub 上翻了一下他的 commit log,的確是個老遊戲了 XD

好像可以推薦大學裡在教 DFA/NFA/RE 的時候可以帶出來?