opnsense / core

OPNsense GUI, API and systems backend
https://opnsense.org/
BSD 2-Clause "Simplified" License
3.07k stars 700 forks source link

MVC/Model - performance overhead when using "constraints" #7509

Closed AdSchellevis closed 3 weeks ago

AdSchellevis commented 3 weeks ago

Important notices

Before you add a new report, we ask you kindly to acknowledge the following:

Describe the bug

After implementing https://github.com/opnsense/core/commit/e36123c99f4ff2a518a927f1807be51186f78577 we seem to have quite some overhead of using standard constraints. Some of them (UniqueConstraint) cause loops in loops, which makes large lists hard to handle.

To Reproduce

  1. In Firewall: Aliases add a couple of thousand items
  2. Edit one and save --> takes seconds to process

Expected behavior

Persisting the data in less than a second.

Describe alternatives you considered

None

Additional context

One of the main culprits seems to be the back reference in the following code:

https://github.com/opnsense/core/blob/79312f47eabd8d55eb776dc6f25bd19d911e0e5e/src/opnsense/mvc/app/models/OPNsense/Base/Constraints/UniqueConstraint.php#L73

Environment

Software version used and hardware type if relevant, e.g.:

OPNsense 24.1.8 (amd64).