performance issue found using xhprof
Closed this issue · 4 comments
williamdes commented
Hi,
While debugging my app with xhprof I did see that email checker is consuming quite a bit of ressources on the request
it seems like the adapter will fire a new ThrowawayDomains
class and so load all the file
Function Name | Calls | Calls% | Incl. Wall Time(microsec) | IWall% | Incl. CPU(microsecs) | ICpu% | Incl.MemUse(bytes) | IMemUse% | Incl.PeakMemUse(bytes) | IPeakMemUse% |
---|---|---|---|---|---|---|---|---|---|---|
Current Function | ||||||||||
EmailChecker\Adapter\BuiltInAdapter::__construct | 1 | 4.8% | 13,161 | 4.6% | 12,000 | 4.3% | 240,704 | 2.2% | 405,664 | 3.7% |
Exclusive Metrics for Current Function | 9 | 0.1% | 0 | 0.0% | 480 | 0.2% | 360 | 0.1% | ||
Parent function | ||||||||||
EmailChecker\EmailChecker::__construct | 1 | 100.0% | 13,161 | 100.0% | 12,000 | 100.0% | 240,704 | 100.0% | 405,664 | 100.0% |
Child functions | ||||||||||
EmailChecker\ThrowawayDomains::__construct | 1 | 25.0% | 13,137 | 99.8% | 12,000 | 100.0% | 238,112 | 98.9% | 405,104 | 99.9% |
spl_autoload_call | 1 | 25.0% | 13 | 0.1% | 0 | 0.0% | 912 | 0.4% | 200 | 0.0% |
EmailChecker\Adapter\ArrayAdapter::__construct | 1 | 25.0% | 1 | 0.0% | 0 | 0.0% | 600 | 0.2% | 0 | 0.0% |
EmailChecker\ThrowawayDomains::toArray | 1 | 25.0% | 1 | 0.0% | 0 | 0.0% | 600 | 0.2% | 0 | 0.0% |
williamdes commented
Solution (temporary ?), register a custom validator that will build the object only when needed
This is the code, a bit custom for some internal reasons, but you get it
<?php
namespace App\Validator;
use EmailChecker\EmailChecker;
class NotThrowAwayValidator
{
public const DESCRIPTION = 'The :attribute domain is invalid.';
public const NAME = 'not_throw_away';
public const MAIN_FUNCTION = 'validateNotThrowAway';
public function validateNotThrowAway(string $attributeName, $value)
{
$emailChecker = new EmailChecker();// Not in a constructor (https://github.com/MattKetmo/EmailChecker/issues/78)
return $emailChecker->isValid($value);
}
}
Important
Disable package from discovery
"extra": {
"laravel": {
"dont-discover": [
"mattketmo/email-checker"
]
}
},
MattKetmo commented
Hello, thanks for your report, I fixed directly the BuiltInAdapter ;)
williamdes commented
Hello, thanks for your report, I fixed directly the BuiltInAdapter ;)
Thanks a lot, let me know when it is released :)
MattKetmo commented
now it is ;)