Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-2159

JSON encoding is slow

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.0.0
    • Affects Version/s: None
    • Component/s: None
    • None

      It seems to have got quite slow. Not sure what is causing it as using Yajl directly doesn't seem to improve it much.

      MongoDB: 2.0.6
      Mongoid 3.0.0.rc

      require 'mongoid'
      require 'benchmark'
      require 'yajl/json_gem'
      
      ENV['MONGOID_ENV'] = 'development'
      
      Mongoid.load!("config/mongoid.yml")
      
      class Facility
        include Mongoid::Document
        include Mongoid::Timestamps
      
        field :name,            :type => String
        field :location,        :type => String
      
      end
      
      @facilities = Facility.all.limit(50).entries
      
      Benchmark.bm do |x|
        x.report("Mongoid") { @a = @facilities.to_json }
        x.report("Parse  ") { @b = JSON.parse(@a) }
        x.report("Encode ") { @b.to_json }
        x.report("Encode ") { Yajl::Encoder.encode(@facilities) }
      end
      

      results

             user     system      total        real
      Mongoid  0.260000   0.000000   0.260000 (  0.262572)
      Parse    0.020000   0.000000   0.020000 (  0.021703)
      Encode   0.010000   0.000000   0.010000 (  0.006516)
      Encode   0.220000   0.000000   0.220000 (  0.238196)
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            aubergene aubergene
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: