Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-1702

Improve Date BSON serialization performance

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • bson-4.5.0
    • Affects Version/s: bson-4.4.2
    • Component/s: BSON
    • Fully Compatible

      Hello!

      I noticed that each Date#to_bson call creates new instance of Time - it's not very problematic, but is noticeable when serializing big amount of Dates.

      I'm attaching small benchmark with proposed improvement (use #jd method and calculate UNIX timestamp * 1000 right there in to_bson method).

      For 1 million dates, it's 0 allocations vs almost 100MB worth of allocations, also this way is about 80% faster.

      Is that OK idea or would that cause some problems?

      Best,
      MichaƂ

        1. date_impr.rb
          1 kB
          Micha?

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            fanfilmu Micha?
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: