Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Optimize Laravel Configuration Loading Process #49313

Closed
wants to merge 4 commits into from

Conversation

sajadsdi
Copy link

@sajadsdi sajadsdi commented Dec 11, 2023

Optimize Laravel Configuration Loading Process

  • Description:

    • Significantly enhances Laravel's configuration loading process to go beyond a mere performance boost.
    • Resolves critical issues that have long hindered flexibility and functionality within Laravel configurations.
    • Ensures configurations are loaded on-demand, mitigating problems associated with the premature loading of all configuration files.
    • Solves challenges related to using helpers, facades, or classes from providers within configurations.
    • Addresses dependency problems, allowing configurations to load in a correct and predictable order.
    • Eliminates the need for workarounds and ensures seamless access to Laravel features within configurations.
  • Benefits:

    • Performance Boost:
      • Demonstrates significant improvements in memory usage and overall system performance.
      • Benchmarks will be provided to quantify performance enhancements.
    • Flexibility and Functionality:
      • Enables dynamic and flexible configuration setups.
      • Resolves issues where certain Laravel features were inaccessible or behaved unexpectedly within configurations.
    • Orderly Configuration Loading:
      • Ensures configurations load in a logical order, resolving dependency problems.
      • Eliminates the need for custom naming conventions or intricate file structuring to control configuration loading order.
    • Seamless Integration:
      • Allows configurations to seamlessly integrate with Laravel's features, including helpers, facades, and classes from providers.
      • Enhances the overall development experience by providing a more intuitive and straightforward configuration setup.
  • Example Scenario:

    • Previously, using certain Laravel features within configurations led to errors or unexpected behaviors due to premature loading.
    • With this optimization, configurations are loaded precisely when needed, allowing smooth integration of Laravel features without any workarounds.
  • Note:

    • This improvement is not limited to performance gains; it addresses fundamental issues, making Laravel more versatile and developer-friendly.
    • Benchmarks will be provided to showcase the tangible performance benefits.

- Enhance the loading bootstrap process by remove loading all files.
- Improve memory usage and performance.
- Improve and change loadConfigurationFiles method
- Improve and change getConfigurationFiles method
…erformance

- Added 'loadedFromCache' variable flag to track whether all configs are loaded from cache.
- Added 'configPath' variable to store the path of config files.
- added configPath param on construct method and add exception for check app config is loaded and set 'configPath' & 'loadedFromCache' properties.
- Implement 'load' method for check and load config if not loaded when configs are not loaded from cache.
- Implement 'getConfigurationFile' method for get file path and file key address to use on 'load' method.
- Implement 'hasMany' method for checking the existence of multiple config keys.
- Update 'get' & 'set' & 'getMany' and 'has' methods to load needed configs (if not loaded) before process.
After change bootstrap config on 'LoadConfiguration' class to don't load all configs, this command cache configs are needed and loaded on booting. for solving this problem:
- Update 'getFreshConfiguration' method to load all config before getting all.
*/
public function __construct(array $items = [])
public function __construct(array $items = [], string $configPath = 'test')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change and would require targeting Laravel 11 (master branch)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not considered a breaking change, and it could be integrated into Laravel 10 without causing fundamental issues. More substantial changes are feasible for Laravel 11 if needed.

@driesvints driesvints changed the title Optimize Laravel Configuration Loading Process [10.x] Optimize Laravel Configuration Loading Process Dec 11, 2023
@taylorotwell
Copy link
Member

taylorotwell commented Dec 11, 2023

Performance optimizations aren't merged without before / after benchmarks of real world applications.

@sajadsdi
Copy link
Author

Sure, I'll work on providing before and after benchmarks for real-world applications to validate the performance optimizations. I'll get back to you with the results shortly.

@sajadsdi
Copy link
Author

sajadsdi commented Dec 11, 2023

@taylorotwell please read pr updated description and if possible, please check the changes, even if we ignore the performance improvement altogether, these changes give more benefits and flexibility to Laravel.

Of course, more optimizations can be done, but it requires more changes and more testing. Currently, my goal is to reduce the limitations of Laravel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants