Skip to content

Performance Issue: Loading All Fields Causes Slowdowns with Large Number of Fields #2637

@gddotorg

Description

@gddotorg

Describe the bug

We’re experiencing a significant performance issue when doing calls to our headless Craft CMS setup. I looked a bit closer and the performance issue caused by the loading of our around 2100 Formie fields every time we fire a call.

I traced the performance bottleneck to the SubmissionQuery class — specifically in the fieldLayouts method when the following line is called:

$layoutFields[] = Formie::$plugin->getFields()->getAllFields();

Inside the getAllFields() function, the most expensive operation occurs during field creation. The loop at line 267 builds all field instances, and the critical part is at line 550:

$fields[] = Formie::$plugin->getFields()->createField($fieldRecord);

This loop appears to instantiate every single field, which becomes very costly when thousands of fields exist. Also it happens all the time when Craft CMS is initializing. So you can see it when working in the backend.

My colleague told me he had a similar issue. Maybe that helps: craftcms/cms#13992

Steps to reproduce

  1. Having 2100 formie fields
  2. Run any backend action
  3. See the delay in the debugger tool under "Timeline"

Form settings

  • Multi-page form: No
  • Submission Method: Ajax
  • Client-side Validation: Yes
  • Custom Form Templates: No

Craft CMS version

5.8.19

Plugin version

3.1.5

Multi-site?

No

Additional context

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions