Service Provider PSR: enhancing ServiceProviderInterface compatibility and performance for major frameworks

100 views
Skip to first unread message

Rasmus Schultz

unread,
Jan 31, 2024, 5:58:14 AMJan 31
to PHP Framework Interoperability Group

Dear Members of the PHP-FIG,

As you may have seen, I have been trying to revive the ServiceProviderInterface proposal.

Since the original proposal was largely rejected by major frameworks such as Symfony and Laravel, I have been trying to understand their reservations, and experimenting with alternatives and improvements.

I'd like to present a potential refactoring of the ServiceProviderInterface, an idea that could address some critical concerns about the performance of standard containers in the context of compiled containers. This idea aims not only to refine the existing concept but also to enhance its appeal and applicability across the wider PHP ecosystem, particularly for larger frameworks.

To my understanding, reservations about the current proposal primarily revolved around the use of callbacks, which posed challenges for optimizations like compiling to static PHP factories or serialization - as well as the necessity for upfront instantiation and registration of providers.

To recap, the current proposal looks essentially like this:

Screenshot 2024-01-31 113702.png

The the idea for a refactored ServiceProviderInterface would look like this:

Screenshot 2024-01-31 113715.png

This refactored interface introduces key changes to address the mentioned concerns:

  1. Replacing Callbacks with Direct Methods: The use of explicit methods (createService and extendService) replaces callable factories and extensions. This approach aligns better with static analysis and compile-time optimizations, potentially enhancing performance.

  2. Utilizing Native PHP Types for Type-Hinting: The refactored interface leverages native PHP types, improving type safety and reducing the reliance on doc-blocks.

  3. Compile-Time Efficiency: Methods like getServiceKeys and getExtensionKeys enable determining services and extensions at compile time, avoiding the need to call and merge keys/value maps in compiled factories at run-time, reducing runtime overhead and memory usage, beneficial for apps with large number of providers.

  4. Flexibility in Service Creation: Allowing for optimizations such as the switch statement within createService and extendService methods, which is especially beneficial for apps/frameworks managing a large number of services.

Before advancing this idea further, I am asking for your preliminary feedback - particularly from the maintainers of major frameworks and compiled containers who rejected the current proposal in the past. Your input is crucial in determining whether this refactored interface could potentially align with your architectural philosophies, optimization strategies, and performance constraints.

  • Would this approach potentially address your performance concerns?
  • Are there any specific aspects of this refactoring that would make integration into your frameworks more feasible?
  • Would you be open to considering adoption if this idea progresses?

If there is positive indication, the next step would be prototyping - adding support for this interface in some container forks, porting some of the existing standard providers, and gathering practical insights.

To be clear, I'm not expecting you to do any of that work. I'm only looking for an indication as to whether this idea could potentially address some of your needs - whether it is worth pursuing.

I understand that the adoption of any provider standard is a significant commitment, and I am not asking for any sort of commitment - just an indication of whether this refactoring might be seen as a better direction.

I believe this proposal still has the potential to add real value for the broad PHP community, and I'm willing to put in some work to try to align it better with the technical and performance aspirations of its major players.

Your input would mean a lot to me.

Thanks,
   Rasmus Schultz


Sergei Predvoditelev

unread,
Jan 31, 2024, 10:33:45 AMJan 31
to PHP Framework Interoperability Group
This proposal looks good, and I would like to make a small clarification.

Arguments "$id"  do not agree with the methods "getServiceKeys()" and "getExtensionKeys()". Maybe rename methods to  "getServiceIds()" and "getExtensionIds()"?

Adrien Crivelli

unread,
Feb 1, 2024, 8:10:51 AMFeb 1
to PHP Framework Interoperability Group
My 2 cents are in favor to rename the parameter $id into $key, and leave the methods names alone.

Rasmus Schultz

unread,
Feb 1, 2024, 8:28:24 AMFeb 1
to php...@googlegroups.com
Changing them is no problem though, it's only in the idea stage.

Rasmus 

--
You received this message because you are subscribed to a topic in the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/php-fig/H0sGx03TfJc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to php-fig+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/660e409a-9ee0-4e39-a41c-118bb9aba20bn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages