fix(UniqueGenerator): prevent memory exhaustion when chaining unique()->optional()#1029
fix(UniqueGenerator): prevent memory exhaustion when chaining unique()->optional()#1029teal-bauer wants to merge 1 commit intoFakerPHP:2.0from
Conversation
…)->optional() When calling unique()->optional()->method(), the __call handler would serialize the returned ChanceGenerator object (which contains the entire Generator with all providers) rather than the final value. This caused exponential memory growth. Adding explicit optional() and valid() methods ensures proper generator chaining - ChanceGenerator now wraps UniqueGenerator, delegating back for actual value generation while preserving uniqueness tracking. Fixes FakerPHP#1027
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 1 week if no further activity occurs. Thank you for your contributions. |
|
Thank you but not thank you? These bots are so disrespectful. |
|
I agree, I would remove the bot, but that would require a review from someone else because I cannot merge my own pull requests, @teal-bauer. |
|
Hm, is there any way to revive this repo (if not project) then? |
|
The general question is whether it makes sense to continue on the path to As of the moment, I would favor the latter to keep the project usable. |
|
I agree. If you look at my fork, I integrated a ton of my patches and tried to go down the 2.x route, but it doesn't seem beneficial enough given the limitations of the PHP engine, so I basically ripped out the 2.x stuff and instead made a hopefully solid 1.x that could become a 2.x just because of all the fixes etc... |
Fixes memory exhaustion when using
unique()->optional()->method()orunique()->valid()->method()chains by adding explicitoptional()andvalid()methods toUniqueGenerator.This is the 2.0 branch counterpart to #1028.
When calling
$faker->unique()->optional()->safeEmail(), theUniqueGenerator::__call()handler would calloptional()on the underlying generator, returning aChanceGenerator, then attempt toserialize()it for uniqueness tracking. TheChanceGeneratorcontains a reference to the entireGeneratorwith all providers, causing massive serialized strings and exponential memory growth.By adding explicit
optional()andvalid()methods toUniqueGenerator,ChanceGeneratornow wrapsUniqueGenerator(not the baseGenerator). When the final method is called, it delegates back toUniqueGenerator, which serializes only the final value (e.g., the email string), not generator objects.Fixes #1027