Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Back to the roots of date

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on.

Back to the roots of date

RubyKaigi 2026 Day 1 talk

Avatar for jinroq

jinroq

April 26, 2026

More Decks by jinroq

Other Decks in Programming

Transcript

  1. Copyright © BizteX Inc All Rights Reserved. 5 h tt

    ps://bugs.ruby-lang.org/issues/21264
  2. Copyright © BizteX Inc All Rights Reserved. 6 h tt

    ps://bugs.ruby-lang.org/issues/21264 • There have been no primary maintainers for the date library and the datetime library for over 10 years. • Maintaining the date library and the datetime library are becoming a burden for Ruby commi tt ers.
  3. Copyright © BizteX Inc All Rights Reserved. 7 Future proposals

    for the date library and the datetime library • The Date class will be deprecated. • Instead, a simpli fi ed The Date class will be created. • Move the Date class into a core class. • Keep the current situation.
  4. Copyright © BizteX Inc All Rights Reserved. 8 Future proposals

    for the date library and the datetime library • The Date class will be deprecated. • Instead, a simpli fi ed The Date class will be created. • Move the Date class into a core class. • Currently, there are no major problems, so Ruby commi tt ers will continue with maintenance that only involves version updates. How did I approach this challenge?
  5. Copyright © BizteX Inc All Rights Reserved. 9 Who are

    you? • Name: ODA Hirohito • X: jimlock • GitHub: jinroq • Community: Fukuoka.rb • Organization: BizteX Inc.
  6. Copyright © BizteX Inc All Rights Reserved. 10 h tt

    ps://www.biztex.co.jp/ We are Hiring!
  7. Copyright © BizteX Inc All Rights Reserved. 16 Ghost said…

    • Moving away from date library: • Decoupling DateTime from Date. • Moving `Time.parse` to the time library to decouple it from date library. • strptime issue.
  8. Copyright © BizteX Inc All Rights Reserved. 17 Ghost said…

    • Moving away from date library: • Decoupling DateTime from Date. -> DateTime is already deprecated, so no major action is required. • Moving `Time.parse` to the time library to decouple it from date library. -> Since `Time.parse` internally calls `Date._parse`, we should port the equivalent of `Date._parse` into the time library. • strptime issue. -> The current implementation is slightly biased toward date, so it should be made more neutral and compact, assuming Time.
  9. Copyright © BizteX Inc All Rights Reserved. 19 h tt

    ps://bugs.ruby-lang.org/issues/21616
  10. Copyright © BizteX Inc All Rights Reserved. 20 h tt

    ps://bugs.ruby-lang.org/issues/21616 • date library will be deprecated. • Porting `Date._parse` to time library. • Porting `Date.strptime` to time library.
  11. Copyright © BizteX Inc All Rights Reserved. 21 h tt

    ps://github.com/ruby/time/compare/ master...jinroq:time:implement_parse_from_date
  12. Copyright © BizteX Inc All Rights Reserved. 22 h tt

    ps://bugs.ruby-lang.org/issues/21616#note-1
  13. Copyright © BizteX Inc All Rights Reserved. 23 h tt

    ps://bugs.ruby-lang.org/issues/21616#note-1 The overly heuristic `Time.parse` is what we want to abolish.
  14. Copyright © BizteX Inc All Rights Reserved. 24 h tt

    ps://www.ruby.or.jp/en/news/20250819
  15. Copyright © BizteX Inc All Rights Reserved. 25 h tt

    ps://www.ruby.or.jp/en/news/20250819 NOT accepted
  16. Copyright © BizteX Inc All Rights Reserved. 26 Judges said…

    • That’s not features we want. • We’d like to stop using the current date implementation if possible.
  17. Copyright © BizteX Inc All Rights Reserved. 27 Reconsider about

    the date library • Should we implement a part of Date's functionality (or a similar independent function) in Time? • If Time can handle dates, how does it di ff er from the already deprecated DateTime?
  18. Copyright © BizteX Inc All Rights Reserved. 28 Reconsider about

    the date library • Should we implement a part of Date's functionality (or a similar independent function) in Time? • If Time can handle dates, how does it di ff er from the already deprecated DateTime? My thoughts are wandering in a labyrinth.
  19. Copyright © BizteX Inc All Rights Reserved. 30 h tt

    ps://github.com/ruby/date/pull/152
  20. Copyright © BizteX Inc All Rights Reserved. 31 h tt

    ps://github.com/ruby/date/commits/master/
  21. Copyright © BizteX Inc All Rights Reserved. 32 It's no

    probrem to incorporate new technologies into established technologies.
  22. Copyright © BizteX Inc All Rights Reserved. 34 Ruby Release

    30th Anniversary Party h tt ps://rubyassociation.doorkeeper.jp/events/190436
  23. Copyright © BizteX Inc All Rights Reserved. 35 Ruby Release

    30th Anniversary Party h tt ps://rubyassociation.doorkeeper.jp/events/190436
  24. Copyright © BizteX Inc All Rights Reserved. 36 If C

    extension of date library were rewri tt en in pure Ruby, we would it be maintainable?
  25. Copyright © BizteX Inc All Rights Reserved. 37 If C

    extension of date library were rewri tt en in pure Ruby, we would it be maintainable? If so, it seems possible.
  26. Copyright © BizteX Inc All Rights Reserved. 38 Jinroq’s idea

    • The date library SHOULD NOT be deprecated. • I would like to ensure compatibility with date library.
  27. Copyright © BizteX Inc All Rights Reserved. 40 What is

    RubyDate? • A project to rewrite the C extension of the date library in pure Ruby. • Only Date class will be rewri tt en.
  28. Copyright © BizteX Inc All Rights Reserved. 43 The day

    before the closing of the RubyKaigi 2026 CFP
  29. Copyright © BizteX Inc All Rights Reserved. 44 The day

    before the closing of the RubyKaigi 2026 CFP
  30. Copyright © BizteX Inc All Rights Reserved. 45 The day

    before the closing of the RubyKaigi 2026 CFP • Development of RubyDate is complete. • Until the end of March 2026 • Date rewriting complete. • Until the end of March 2027
  31. Copyright © BizteX Inc All Rights Reserved. 46 RubyDate development

    plan • Used an AI agent • Started by porting ruby/date/ext/date/date_core.c. • Implemented it by referring to the behavior described in the usage comments. • Ported some of the tests from ruby/date/test/date/test_date.rb, and then had an AI agent write the rest of the tests. • Development environment • 4.1-dev • Ubuntu 24.04 LTS
  32. Copyright © BizteX Inc All Rights Reserved. 47 First commit

    • Class Methods • jd • gregorian_leap? • julian_leap? • ordinal • Instance Methods • initialize • year • month/mon • day/mday • jd • start • <=> • == • eql? • hash? • +(n) • in fi nite?
  33. Copyright © BizteX Inc All Rights Reserved. 48 Development of

    RubyDate • Together with an AI agent, I diligently implemented the Date methods into RubyDate.
  34. Copyright © BizteX Inc All Rights Reserved. 52 Ported test_date.rb

    from the date library to ruby_date. All RED😱
  35. Copyright © BizteX Inc All Rights Reserved. 53 Investigation of

    causes • Tests that had been partially ported from test_date.rb were somehow deleted by the AI agent. • The AI ​​ agent was only adding tests that passed the logic it had implemented.
  36. Copyright © BizteX Inc All Rights Reserved. 54 Investigation of

    causes • Tests that had been partially ported from test_date.rb were somehow deleted by the AI agent. • The AI ​​ agent was only adding tests that passed the logic it had implemented. • All test code under ruby/date/test/date has been moved to ruby_date. • Only the tests in test_date.rb have been fi xed to pass.
  37. Copyright © BizteX Inc All Rights Reserved. 57 The ruby_date

    gem was complete! • Development of RubyDate is complete. • Until the end of March 2026 • Date rewriting complete. • Until the end of March 2027
  38. Copyright © BizteX Inc All Rights Reserved. 58 Shouldn't I

    rewrite the C extension of Date in pure Ruby?
  39. Copyright © BizteX Inc All Rights Reserved. 59 Shouldn't I

    rewrite the C extension of Date in pure Ruby? I see no reason not to move forward.
  40. Copyright © BizteX Inc All Rights Reserved. 60 RubyDate vs

    Date • Supported Ruby version • RubyDate: 3.0 or later • Date: 2.6 or later • Presence or absence of DateTime • RubyDate: absence • Date: presence
  41. Copyright © BizteX Inc All Rights Reserved. 62 h tt

    ps://docs.ruby-lang.org/en/4.0/DateTime.html
  42. Copyright © BizteX Inc All Rights Reserved. 65 Pitfall #1

    ruby/date/ext/date_core.c Tests don’t pass😇
  43. Copyright © BizteX Inc All Rights Reserved. 66 Pitfall #1

    • Cause • Date refers to the pure Ruby implementation. • DateTime's instance variables access the C extension implementation.
  44. Copyright © BizteX Inc All Rights Reserved. 67 Pitfall #1

    • Solution • date_core.c: Incorporate pure Ruby Date implementation into DateTime. • DateTime: Move toward a full pure Ruby implementation.
  45. Copyright © BizteX Inc All Rights Reserved. 68 Pitfall #1

    • Solution • date_core.c: Incorporate pure Ruby Date implementation into DateTime. • DateTime: Move toward a full pure Ruby implementation.
  46. Copyright © BizteX Inc All Rights Reserved. 70 Pitfall #2

    ruby/date/test/date/test_date_parse.rb
  47. Copyright © BizteX Inc All Rights Reserved. 71 Pitfall #2

    ruby/date/test/date/test_date_parse.rb
  48. Copyright © BizteX Inc All Rights Reserved. 72 Pitfall #2

    ruby/date/test/date/test_date_parse.rb Failed tests on Ruby ≤ 3.2😇
  49. Copyright © BizteX Inc All Rights Reserved. 73 Pitfall #2

    • Cause • Historically, Ruby's Regexp processing has been relatively slow. • Ruby 3.3 introduced dramatic performance improvements for Regexp.
  50. Copyright © BizteX Inc All Rights Reserved. 74 Pitfall #2

    • Solution • Ruby 3.3+ → Use pure Ruby Date • Ruby 3.2 & below → Use C extension Date
  51. Copyright © BizteX Inc All Rights Reserved. 76 h tt

    ps://github.com/ruby/date/pull/155
  52. Copyright © BizteX Inc All Rights Reserved. 80 The game

    of chicken started: Will PR #155 be merged by my talk of RubyKaigi 2026?
  53. Copyright © BizteX Inc All Rights Reserved. 82 First review

    comment You need to provide comprehensive benchmarks showing that performance does not decrease signi fi cantly.
  54. Copyright © BizteX Inc All Rights Reserved. 83 First review

    comment You need to provide comprehensive benchmarks showing that performance does not decrease signi fi cantly. I forget it…😇
  55. Copyright © BizteX Inc All Rights Reserved. 84 Pure Ruby

    Date Benchmark .FUIPE $FYU JT 3VCZ JT 3VCZ$ %BUFKE . ,  %BUFPSEJOBM . ,  %BUFDPNNFSDJBM . , 
  56. Copyright © BizteX Inc All Rights Reserved. 85 Pure Ruby

    Date Benchmark • Cause • Focused solely on rewriting the C implementation in pure Ruby.
  57. Copyright © BizteX Inc All Rights Reserved. 87 Pure Ruby

    Date Benchmark .FUIPE $FYU JT CFGPSF3VCZ JT BGUFS3VCZ JT BGUFS3VCZ$ %BUFUPEBZ ,  ,  %BUF@QBSTF JTP ,  ,  %BUFQBSTF JTP ,  ,  %BUFTUSQUJNF .  ,  %BUFTUSGUJNF .  .  %BUFDJWJM .  .  %BUFKE . , .  %BUFPSEJOBM . , ,  %BUFDPNNFSDJBM . , , 
  58. Copyright © BizteX Inc All Rights Reserved. 89 Another review

    comment The current extension is line-by-line translation from Ruby to C and not optimized for C.
  59. Copyright © BizteX Inc All Rights Reserved. 90 Another review

    comment The current extension is line-by-line translation from Ruby to C and not optimized for C. 💡
  60. Copyright © BizteX Inc All Rights Reserved. 91 Another review

    comment The current extension is line-by-line translation from Ruby to C and not optimized for C. 💡 Burn it all down and build it again.
  61. Copyright © BizteX Inc All Rights Reserved. 92 The Trigger

    for a Clean Slate • AI agents boosted development speed more than I ever imagined. • Working with AI agents gave me a much higher resolution of how date works.
  62. Copyright © BizteX Inc All Rights Reserved. 93 Shift in

    Implementation Approach • The Rules for AI agent: • Zero changes to tests. (Maintain the ground truth) • Target: 85%+ performance of C extension. • The Process: • Identify bo tt lenecks method by method. • Apply micro-optimizations.
  63. Copyright © BizteX Inc All Rights Reserved. 94 Shift in

    Implementation Approach • The Rules for AI agent: • Zero changes to tests. (Maintain the ground truth) • Target: 85%+ performance of C extension. • The Process: • Identify bo tt lenecks method by method. • Apply micro-optimizations. These optimizations didn't move the needle as much as I expected.
  64. Copyright © BizteX Inc All Rights Reserved. 95 Shift in

    Implementation Approach • The Rules for AI agent: • Zero changes to tests. (Maintain the ground truth) • Target: 85%+ performance of C extension. • The Process: • Identify bo tt lenecks method by method. • Apply micro-optimizations. And then, I arrived at a single truth.
  65. Copyright © BizteX Inc All Rights Reserved. 96 The truth

    is... YJIT was disabled the whole time.
  66. Copyright © BizteX Inc All Rights Reserved. 97 Pure Ruby(+YJIT)

    Date Benchmark .FUIPE $FYU JT 3VCZ JT 3VCZ :+*5 JT 3VCZ :+*5$ %BUFUPEBZ , , ,  %BUF@QBSTF JTP , , .  %BUFQBSTF JTP , , .  %BUFTUSQUJNF . , .  %BUFTUSGUJNF . . .  %BUFDJWJM . . .  %BUFKE . . .  %BUFPSEJOBM . , .  %BUFDPNNFSDJBM . , . 
  67. Copyright © BizteX Inc All Rights Reserved. 98 Pure Ruby(+YJIT)

    Date Benchmark .FUIPE $FYU JT 3VCZ JT 3VCZ :+*5 JT 3VCZ :+*5$ %BUFUPEBZ , , ,  %BUF@QBSTF JTP , , .  %BUFQBSTF JTP , , .  %BUFTUSQUJNF . , .  %BUFTUSGUJNF . . .  %BUFDJWJM . . .  %BUFKE . . .  %BUFPSEJOBM . , .  %BUFDPNNFSDJBM . , .  🙌
  68. Copyright © BizteX Inc All Rights Reserved. 100 Is Jinroq

    prepared to maintain this source code for years to come?
  69. Copyright © BizteX Inc All Rights Reserved. 101 Is Jinroq

    prepared to maintain this source code for years to come? 😇
  70. Copyright © BizteX Inc All Rights Reserved. 103 Restraining optimization

    • Improve readability and maintainability • Eliminated `getbyte` byte-level manipulation. • Switched to StringScanner and regex for clearer logic.
  71. Copyright © BizteX Inc All Rights Reserved. 104 Pure Ruby(+YJIT)

    Date Benchmark .FUIPE $FYU :+*5 JT 3VCZ :+*5 JT 3VCZ$ %BUF@TUSQUJNF . .  %BUFTUSQUJNF . .  %BUFTUSQUJNF DPNQMFY . . 
  72. Copyright © BizteX Inc All Rights Reserved. 108 Approaches to

    refactor Date._strptime • `$~.get_int(1)`
  73. Copyright © BizteX Inc All Rights Reserved. 109 h tt

    ps://bugs.ruby-lang.org/issues/21932
  74. Copyright © BizteX Inc All Rights Reserved. 110 h tt

    ps://github.com/ruby/ruby/pull/16300 get_int -> integer_at
  75. Copyright © BizteX Inc All Rights Reserved. 111 h tt

    ps://bugs.ruby-lang.org/issues/21943
  76. Copyright © BizteX Inc All Rights Reserved. 112 h tt

    ps://github.com/ruby/strscan/pull/193
  77. Copyright © BizteX Inc All Rights Reserved. 113 MatchData#integer_at VS

    StringScanner#integer_at .FUIPE 3VCZ :+*5 JT .BUDI%BUBJOUFHFS@BU 4USJOH4DBOOFSJOUFHF S@BU %BUF@TUSQUJNF    %BUFTUSQUJNF    %BUFTUSQUJNF DPNQMFY   
  78. Copyright © BizteX Inc All Rights Reserved. 117 Conclusion •

    Jinroq would like to avoid deprecating the date library. • However, it's easier said than done. • AI agents enable us to build products with incredible speed. • Therefore, there is no compelling reason to wait. • AI agents are powerful partners, but NEVER our masters. • We MUST remain accountable for what we build.
  79. Copyright © BizteX Inc All Rights Reserved. 118 Special Thanks

    • narse, znz • nobu, jeremyevans • tompng • and more…