Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

There was a problem

You must be a member of this account.

This project is archived and is in readonly mode.

DateTime#to_json is slow.

#598

The DateTime#to_json method is extremely slow. Converting ~6700 AR objects (with two datetime fields each) to JSON takes roughly 18 seconds on a 2.2GHz Core 2 Duo machine.

This patch simplifies the code, avoiding excessive string operations. End result is about a 5x improvement (~18 to ~2 seconds).

Reported by Alex Zepeda · July 10th, 2008 @ 07:34 PM

State: resolved
Milestone: 2.x
Assigned to: Jeremy Kemper Jeremy Kemper
Importance: none

Activity

  1. Alex Zepeda
    Alex Zepeda
    • Title changed from Time#to_json to Time#to_json is slow.

    July 10th, 2008 @ 07:34 PM

  2. Cheah Chu Yeow
    Cheah Chu Yeow

    This looks good but it's slightly outdated because it's diffed against the old SVN version of Rails). Don't think Jeremy will have a problem with that though :)

    July 11th, 2008 @ 03:06 AM

  3. Ripta Pasay
    Ripta Pasay
    • Title changed from Time#to_json is slow. to DateTime#to_json is slow.
    • Tag changed from 2.0-stable, activerecord, patch to 2.0-stable, activesupport, patch

    Benchmarking the changes, I could only get about a 0.25% speed-up at best. I agree the string operation is unnecessary and there was a speed-up, but it seems negligible over a large number of iterations.

    n = 100,000
                  user     system      total        real
    original 62.240000   0.090000  62.330000 ( 62.431844)
    patched  62.090000   0.090000  62.180000 ( 62.276596)
    

    Benchmark attached, in case I missed something.

    July 12th, 2008 @ 10:25 PM

  4. Repository
    Repository

    (from [9783e66cade4d145389cca18fab822f44d03161a]) Slightly faster DateTime#to_json. [#598 state:resolved] [Alex Zepeda]

    http://github.com/rails/rails/co...

    July 14th, 2008 @ 01:44 AM

  5. Pratik
    Pratik
    • State changed from new to resolved

    July 14th, 2008 @ 03:03 AM

  6. Repository
    Repository

    (from [50c73c2dfd0d5eb880426e7bc385bcee004ffe3e]) Slightly faster DateTime#to_json. [#598 DateTime#to_json is slow. state:resolved] [Alex Zepeda] http://github.com/rails/rails/co...

    August 25th, 2008 @ 09:27 AM