PHP › Performance Optimization & OPcache
How does lazy loading versus eager loading of resources and how minimizing unnecessary work within a request's critical path help improve overall PHP application response times?
IntermediateAnswer
Beyond database queries specifically, general performance optimization involves ensuring expensive operations, such as calling an external API or performing a complex calculation, only happen when their result is genuinely needed rather than unconditionally on every request, deferring non essential work to a background job queue whenever the user does not need to wait for it to complete immediately, and being mindful about loading only the specific classes, configuration, or data actually required for handling a given request rather than unconditionally initializing everything upfront.
// Deferring non essential work to a background queue
Order::create($data);
SendOrderConfirmationEmail::dispatch($order); // queued, not blocking the responseReal-world example An order processing endpoint immediately returns a response to the customer once the order is successfully created, dispatching the confirmation email sending as a background queued job rather than making the customer wait for that email to actually be sent before receiving their confirmation.