去年有寫過 Ruby 的 YJIT 帶來的效能提昇:「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.