© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
27 replies
Shavik

->fillForm is very slow in tests

I'm working on writing some feature/integration tests a simple Filament App.
It tracks 'people'. I have the following test that should test that a user can be created.

My problem is the
->fillForm
->fillForm
method is very slow. It takes around 20 seconds to run.

This code look scarier than it should as I've broken many things down to time them.
it('can create person', function () {
    $personData = Person::factory()->make();
    $personData->load('physicalAddress');

    $addressData = Address::factory()->type(AddressType::PHYSICAL)->make();
    $formData = array_merge($personData->toArray(), ['physicalAddress' => $addressData->toArray()]);
    if ($personData->height_inches !== null) {
        $formData['feet'] = (int)floor($personData->height_inches / 12);
        $formData['inches'] = $personData->height_inches % 12;
    }
    dump($formData);

    dump('performing livewire request.');
    $livewire = livewire(PersonResource\Pages\CreatePerson::class);

    DB::connection()->enableQueryLog();
    $start = microtime(true);
    $livewire->fillForm($formData);
    dump('fillForm: ' . round((microtime(true) - $start), 2) . " seconds");


    $start = microtime(true);
    $livewire->call('create');
    dump('call: ' . round((microtime(true) - $start), 2) . " seconds");

    $start = microtime(true);
    $livewire->assertHasNoFormErrors();
    dump('assertHasNoFormErrors: ' . round((microtime(true) - $start), 2) . " seconds");

    $queries = DB::getRawQueryLog();
    dump($queries);

    dump('checking database...');
    $this->assertDatabaseHas(Person::class, $personData->withoutRelations()->toArray());
    $addressData->setAppends([]);
    $this->assertDatabaseHas(Address::class, $addressData->toArray());
});
it('can create person', function () {
    $personData = Person::factory()->make();
    $personData->load('physicalAddress');

    $addressData = Address::factory()->type(AddressType::PHYSICAL)->make();
    $formData = array_merge($personData->toArray(), ['physicalAddress' => $addressData->toArray()]);
    if ($personData->height_inches !== null) {
        $formData['feet'] = (int)floor($personData->height_inches / 12);
        $formData['inches'] = $personData->height_inches % 12;
    }
    dump($formData);

    dump('performing livewire request.');
    $livewire = livewire(PersonResource\Pages\CreatePerson::class);

    DB::connection()->enableQueryLog();
    $start = microtime(true);
    $livewire->fillForm($formData);
    dump('fillForm: ' . round((microtime(true) - $start), 2) . " seconds");


    $start = microtime(true);
    $livewire->call('create');
    dump('call: ' . round((microtime(true) - $start), 2) . " seconds");

    $start = microtime(true);
    $livewire->assertHasNoFormErrors();
    dump('assertHasNoFormErrors: ' . round((microtime(true) - $start), 2) . " seconds");

    $queries = DB::getRawQueryLog();
    dump($queries);

    dump('checking database...');
    $this->assertDatabaseHas(Person::class, $personData->withoutRelations()->toArray());
    $addressData->setAppends([]);
    $this->assertDatabaseHas(Address::class, $addressData->toArray());
});


The output is the following:
"performing livewire request." // tests/Feature/PersonTest.php:43
"fillForm: 20.66 seconds" // tests/Feature/PersonTest.php:54
"call: 0.44 seconds" // tests/Feature/PersonTest.php:59
"assertHasNoFormErrors: 0.4 seconds" // tests/Feature/PersonTest.php:63
array:5 [ // tests/Feature/PersonTest.php:66
  0 => array:2 [
    "raw_query" => "insert into "people" ("first_name", "middle_name", "last_name", "maternal_last_name", "gender", "birthday", "place_of_birth", "weight_pounds", "eye_color", "hair_color", "email", "home_phone", "cell_phone", "marketing_comms_enabled", "update_comms_enabled", "user_id", "updated_at", "created_at") values ('Zoey', null, 'Rath', 'McLaughlin', 'female', '1926-07-06', 'Corkeryfurt', 152, null, null, 'waters.mable@example.net', '(914) 319-7774', '+1-316-757-2317', 0, 0, 1, '2023-09-18 22:19:37', '2023-09-18 22:19:37')"
    "time" => 0.09
  ]
  1 => array:2 [
    "raw_query" => "insert into "addresses" ("type", "street", "suite", "city", "state", "zip", "updated_at", "created_at") values ('physical', '700 Gustave Light Suite 860', null, 'Port Devon', 'MO', '87688', '2023-09-18 22:19:37', '2023-09-18 22:19:37')"
    "time" => 0.07
  ]
  2 => array:2 [
    "raw_query" => "update "people" set "physical_address_id" = 1, "updated_at" = '2023-09-18 22:19:37' where "id" = 1"
    "time" => 0.04
  ]
  3 => array:2 [
    "raw_query" => "insert into "addresses" ("type", "street", "suite", "city", "state", "zip", "updated_at", "created_at") values ('mailing', null, null, null, null, null, '2023-09-18 22:19:37', '2023-09-18 22:19:37')"
    "time" => 0.04
  ]
  4 => array:2 [
    "raw_query" => "update "people" set "mailing_address_id" = 2, "updated_at" = '2023-09-18 22:19:37' where "id" = 1"
    "time" => 0.03
  ]
]
"checking database..." // tests/Feature/PersonTest.php:68

   PASS  Tests\Feature\PersonTest
"performing livewire request." // tests/Feature/PersonTest.php:43
"fillForm: 20.66 seconds" // tests/Feature/PersonTest.php:54
"call: 0.44 seconds" // tests/Feature/PersonTest.php:59
"assertHasNoFormErrors: 0.4 seconds" // tests/Feature/PersonTest.php:63
array:5 [ // tests/Feature/PersonTest.php:66
  0 => array:2 [
    "raw_query" => "insert into "people" ("first_name", "middle_name", "last_name", "maternal_last_name", "gender", "birthday", "place_of_birth", "weight_pounds", "eye_color", "hair_color", "email", "home_phone", "cell_phone", "marketing_comms_enabled", "update_comms_enabled", "user_id", "updated_at", "created_at") values ('Zoey', null, 'Rath', 'McLaughlin', 'female', '1926-07-06', 'Corkeryfurt', 152, null, null, 'waters.mable@example.net', '(914) 319-7774', '+1-316-757-2317', 0, 0, 1, '2023-09-18 22:19:37', '2023-09-18 22:19:37')"
    "time" => 0.09
  ]
  1 => array:2 [
    "raw_query" => "insert into "addresses" ("type", "street", "suite", "city", "state", "zip", "updated_at", "created_at") values ('physical', '700 Gustave Light Suite 860', null, 'Port Devon', 'MO', '87688', '2023-09-18 22:19:37', '2023-09-18 22:19:37')"
    "time" => 0.07
  ]
  2 => array:2 [
    "raw_query" => "update "people" set "physical_address_id" = 1, "updated_at" = '2023-09-18 22:19:37' where "id" = 1"
    "time" => 0.04
  ]
  3 => array:2 [
    "raw_query" => "insert into "addresses" ("type", "street", "suite", "city", "state", "zip", "updated_at", "created_at") values ('mailing', null, null, null, null, null, '2023-09-18 22:19:37', '2023-09-18 22:19:37')"
    "time" => 0.04
  ]
  4 => array:2 [
    "raw_query" => "update "people" set "mailing_address_id" = 2, "updated_at" = '2023-09-18 22:19:37' where "id" = 1"
    "time" => 0.03
  ]
]
"checking database..." // tests/Feature/PersonTest.php:68

   PASS  Tests\Feature\PersonTest



As you can see, there are no slow queries and I've isolated the slowness to the
->fillForm
->fillForm
method. I can't see to figure out why that would be slowing things down to badly.

Any help would be greatly appreciated!
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

SpatieMediaLibraryFileUpload - Display is very slow
FilamentFFilament / ❓┊help
2y ago
Very slow app
FilamentFFilament / ❓┊help
2y ago
very Slow The request is pending
FilamentFFilament / ❓┊help
2y ago
Table action edit modal is very slow
FilamentFFilament / ❓┊help
3y ago