factory_bot
factory_bot copied to clipboard
Populating an `hstore` in Factories causes a significant slowdown
Description
I've noticed a significant performance hit when running rspec tests whenever there is a factory that populates an hstore column.
Reproduction Steps
Create an hstore column and set it like so:
FactoryBot.define do
factory :artifact do
subject { 'foo_subject' }
subject_address { { 'street' => Faker::Address.street_address } }
end
end
When an rspec test uses this factory with subject_address commented out, the test runs 3-6x faster. An example test to demonstrate the speed difference could be as simple as:
RSpec.describe Example do
let(:artifact) { create(:artifact) }
it 'does something' { artifact }
end
### System configuration
**factory_bot version**: 6.2.0
**rails version**: 7.0.3.1
**ruby version**: 3.1.2p20
Given the factory definition in your comment, calling create(:artifact) is equivalent to:
artifact = Artifact.new
artifact.subject = "foo_subject"
artifact.subject_address = { 'street' => Faker::Address.street_address }
artifact.save!
Do you see the same slowdown if you run that instead of create(:artifact)?