Log format performance improvement

未关闭
#139 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
重构
描述清晰度
基本清楚
活跃度
停滞
技术栈
ruby
领域
observability

调研方向

从 lib/logger/formatter.rb 第 22 行附近开始,检查当前时间戳格式的使用方式。运行提供的 Benchmark.ips 对比,然后确定所提议的 iso8601(6) 输出是否与 logger 预期的格式兼容,并在修改之前记录结果。

由索引模型根据 Issue 内容生成。

描述

While doing some log format configuration, I came across this performance improvement. It is 4.61x slower to use strftime compared to iso8601(6). The output format is not identical, but close and has a small improvement that it includes offset IMO. Was wondering if this improvement is worth making a PR?

irb(main):9> time = Time.now
2025-10-10 09:28:08.27533 -0400

irb(main):10> time.strftime("%Y-%m-%dT%H:%M:%S.%6N")
"2025-10-10T09:28:08.275330"

irb(main):11> time.iso8601(6)
"2025-10-10T09:28:08.275330-04:00"
Warming up --------------------------------------
       Time#strftime   149.661k i/100ms
        Time#iso8601   668.851k i/100ms
Calculating -------------------------------------
       Time#strftime      1.459M (± 4.5%) i/s -      7.333M in   5.038060s
        Time#iso8601      6.731M (± 3.8%) i/s -     34.111M in   5.077102s

Comparison:
        Time#iso8601:  6730815.9 i/s
       Time#strftime:  1459156.6 i/s - 4.61x  (± 0.00) slower
Benchmark.ips do |x|
  time = Time.now
  x.report('Time#strftime') { time.strftime('%Y-%m-%dT%H:%M:%S.%6N') }
  x.report('Time#iso8601') { time.iso8601(6) }
  x.compare!
end

https://github.com/ruby/logger/blob/7827b54b0dd796891a508021146607076770b2fb/lib/logger/formatter.rb#L22

主要语言
Ruby
星标
161
派生
76
平均合并
2 天 5 小时
30 天内合并 PR
3

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ruby/logger 的其他 Issue

查看 ruby/logger 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。