Severe performance degradation in 9.0.5

XMLWordPrintableJSON

    • Ruby Drivers
    • Not Needed
    • None
    • None
    • None
    • None
    • None
    • None

      COPIED FROM https://github.com/mongodb/mongoid/discussions/5955

       

      The same code (a simple loop that executes a few hundred save!) that runs in 2s with 9.0.4 takes more than 30s with 9.0.5.
      I just switch versions in bundle, re run and performance goes to hell!
      I had also updated Ruby to 3.4.1 and thought that could have been that but, after downgrading Ruby to the previous version, the issue was still there.

      Update 1:
      Ok, I started testing my code with every mongoid commit after the v9.0.4 tag and the issue was introduced in 86f49a5

      Update 2:
      I've installed 9.0.5 again, edited the gem by reverting just the change introduced in 86f49a5 and everything performs fine as always. So there it is the problem!

      Code to reproduce

      Mongoid.configure do |config|
        config.clients.default = {
          hosts: ['localhost:27017'],
          database: 'mongoid_test',
        }
      end
      
      class Ubicacion
        include Mongoid::Document
      
        store_in collection: "ubicaciones"
      
        field :descripcion
      end
      
      class Almacenamiento < Ubicacion
        field :capacidad, type: Integer
      end
      
      class Contenedor < Ubicacion
        # no Mongoid stuff here, just domain-specific behavior
      end
      
      class Celda < Almacenamiento
        field :x, type: Integer
        field :y, type: Integer
      
        belongs_to :rack, class_name: "Rack"
      end
      
      class Rack < Contenedor
        has_many :celdas, class_name: Celda, inverse_of: :rack
      end
      
      Benchmark.bm do |r|
        r.report("save!") do
          10.times do
            rack = Rack.new(descripcion: "Rack")
            rack.save!
            (0...15).each do |x|
              (0...15).each do |y|
                celda = Celda.new(x:, y:, rack:)
                rack.celdas << celda
                celda.save!
              end
            end
          end
        end
      end 

      Benchmark output

      9.0.5
                 user     system      total        real
      save! 13.816966   0.131370  13.948336 ( 27.090546)
      9.0.4
                 user     system      total        real
      save!  5.802399   0.371745   6.174144 ( 20.193390)
      

              Assignee:
              Jamis Buck
              Reporter:
              Dmitry Rybakov
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: