Skip to content

[10.x] The validator is very slow with large datasets when the key contains asterisks #49375

@eusonlito

Description

@eusonlito

Laravel Version

10.37.3

PHP Version

8.3.0

Database Driver & Version

No response

Description

As reported on previous Laravel versions, the laravel Validator is very very slow with large datasets:

I have tried to understand and review the validation process, but it is too complex to be able to send a PR. I could only find that it iterates thousands of times over all values when calculating the validation rules. The problem seems to come only when using asterisks in the fields to validate.

Here a tweet with some tests: https://twitter.com/lito_ordes/status/1735082009666494594

And the repo to test: https://github.com/eusonlito/laravel-validator-slow

Steps To Reproduce

Tests Results

"Read Data Time: 0.0120"
"Items: 11351"
"validatorAsterisk Time: 61.9842"
"validatorFixed Prepare: 0.0048"
"validatorFixed Time: 0.1179"
"validatorChunks1000 Time: 2.1746"
"validatorChunks5000 Time: 10.9196"
"validatorChunks10000 Time: 46.9144"

Added memory usage and chunks

"Read Data: 0.0120 seconds / 32.00 memory"
"Items: 11351"
"validatorAsterisk: 60.9496 seconds / 68.50 memory"
"rulesFixed: 0.0049 seconds / 60.50 memory"
"validatorFixed: 0.1193 seconds / 74.00 memory"
"validatorChunks100: 0.3551 seconds / 64.00 memory"
"validatorChunks1000: 2.1089 seconds / 66.00 memory"
"validatorChunks5000: 10.5173 seconds / 70.00 memory"
"validatorChunks10000: 46.5916 seconds / 77.50 memory"

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