Skip to content

Commit ddd8a24

Browse files
committed
Improve class mapping
1 parent 889fb47 commit ddd8a24

27 files changed

+383
-164
lines changed

bench/composer.json

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"require": {
33
"php": "^8.1",
44
"psr/simple-cache": "^1.0|^2.0|^3.0",
5-
"type-lang/parser": "^1.2",
6-
"type-lang/printer": "^1.2"
5+
"type-lang/parser": "^1.5",
6+
"type-lang/printer": "^1.3"
77
},
88
"autoload": {
99
"psr-4": {
@@ -12,24 +12,26 @@
1212
}
1313
},
1414
"require-dev": {
15-
"cuyz/valinor": "^1.13",
16-
"jms/serializer": "^3.30",
17-
"phpbench/phpbench": "^1.3",
18-
"phpdocumentor/reflection-docblock": "^5.4",
19-
"phpdocumentor/type-resolver": "^1.8",
15+
"cuyz/valinor": "^1.17",
16+
"jms/serializer": "^3.32",
17+
"phpbench/phpbench": "^1.4",
18+
"phpdocumentor/reflection-docblock": "^5.6",
19+
"phpdocumentor/type-resolver": "^1.10",
2020
"symfony/cache": "^5.4|^6.0|^7.0",
2121
"symfony/property-access": "^5.4|^6.0|^7.1",
2222
"symfony/serializer": "^5.4|^6.0|^7.1",
2323
"type-lang/phpdoc": "^1.0",
2424
"type-lang/phpdoc-standard-tags": "^1.0",
25-
"symfony/var-dumper": "^7.1"
25+
"symfony/var-dumper": "^5.4|^6.0|^7.1"
2626
},
2727
"scripts": {
2828
"bench": [
29-
"phpbench run --report=default --tag=current --progress=none --filter=benchNormalization",
30-
"phpbench run --report=default --tag=current --progress=none --filter=benchCachedNormalization",
31-
"phpbench run --report=default --tag=current --progress=none --filter=benchDenormalization",
32-
"phpbench run --report=default --tag=current --progress=none --filter=benchCachedDenormalization"
29+
"phpbench run --report=default --tag=current --filter=benchInstantiate",
30+
"phpbench run --report=default --tag=current --filter=benchExtract",
31+
"phpbench run --report=default --tag=current --filter=benchNormalization",
32+
"phpbench run --report=default --tag=current --filter=benchCachedNormalization",
33+
"phpbench run --report=default --tag=current --filter=benchDenormalization",
34+
"phpbench run --report=default --tag=current --filter=benchCachedDenormalization"
3335
]
3436
},
3537
"minimum-stability": "dev",
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\Mapper\Bench\Extractor;
6+
7+
abstract class ExtractorBenchmark
8+
{
9+
abstract public function benchExtract(): void;
10+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\Mapper\Bench\Extractor;
6+
7+
use PhpBench\Attributes\BeforeMethods;
8+
use PhpBench\Attributes\Iterations;
9+
use PhpBench\Attributes\Revs;
10+
use PhpBench\Attributes\Warmup;
11+
use TypeLang\Mapper\Runtime\Extractor\NativeTypeExtractor;
12+
13+
#[Revs(50), Warmup(5), Iterations(20), BeforeMethods('prepare')]
14+
final class NativeExtractorBench extends ExtractorBenchmark
15+
{
16+
private readonly NativeTypeExtractor $extractor;
17+
18+
public function prepare(): void
19+
{
20+
$this->extractor = new NativeTypeExtractor();
21+
}
22+
23+
public function benchExtract(): void
24+
{
25+
$this->extractor->getDefinitionByValue(null);
26+
$this->extractor->getDefinitionByValue(true);
27+
$this->extractor->getDefinitionByValue(false);
28+
$this->extractor->getDefinitionByValue(\NAN);
29+
$this->extractor->getDefinitionByValue(42);
30+
$this->extractor->getDefinitionByValue(42.0);
31+
$this->extractor->getDefinitionByValue([1,2,3]);
32+
$this->extractor->getDefinitionByValue((object)[1,2,3]);
33+
}
34+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\Mapper\Bench\Instantiator;
6+
7+
use PhpBench\Attributes\BeforeMethods;
8+
use PhpBench\Attributes\Iterations;
9+
use PhpBench\Attributes\Revs;
10+
use PhpBench\Attributes\Warmup;
11+
use TypeLang\Mapper\Bench\Stub\ExampleRequestDTO;
12+
use TypeLang\Mapper\Runtime\ClassInstantiator\CloneClassInstantiator;
13+
use TypeLang\Mapper\Runtime\ClassInstantiator\ReflectionClassInstantiator;
14+
15+
#[Revs(50), Warmup(5), Iterations(20), BeforeMethods('prepare')]
16+
final class CloneInstantiatorBench extends InstantiatorBenchmark
17+
{
18+
private readonly CloneClassInstantiator $instantiator;
19+
20+
public function prepare(): void
21+
{
22+
$this->instantiator = new CloneClassInstantiator(
23+
delegate: new ReflectionClassInstantiator(),
24+
);
25+
}
26+
27+
public function benchInstantiate(): void
28+
{
29+
$this->instantiator->instantiate(ExampleRequestDTO::class);
30+
}
31+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\Mapper\Bench\Instantiator;
6+
7+
use Doctrine\Instantiator\Instantiator;
8+
use Doctrine\Instantiator\InstantiatorInterface;
9+
use PhpBench\Attributes\BeforeMethods;
10+
use PhpBench\Attributes\Iterations;
11+
use PhpBench\Attributes\Revs;
12+
use PhpBench\Attributes\Warmup;
13+
use TypeLang\Mapper\Bench\Stub\ExampleRequestDTO;
14+
15+
#[Revs(50), Warmup(5), Iterations(20), BeforeMethods('prepare')]
16+
final class DoctrineInstantiatorBench extends InstantiatorBenchmark
17+
{
18+
private readonly InstantiatorInterface $instantiator;
19+
20+
public function prepare(): void
21+
{
22+
$this->instantiator = new Instantiator();
23+
}
24+
25+
public function benchInstantiate(): void
26+
{
27+
$this->instantiator->instantiate(ExampleRequestDTO::class);
28+
}
29+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\Mapper\Bench\Instantiator;
6+
7+
abstract class InstantiatorBenchmark
8+
{
9+
abstract public function benchInstantiate(): void;
10+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypeLang\Mapper\Bench\Instantiator;
6+
7+
use PhpBench\Attributes\BeforeMethods;
8+
use PhpBench\Attributes\Iterations;
9+
use PhpBench\Attributes\Revs;
10+
use PhpBench\Attributes\Warmup;
11+
use TypeLang\Mapper\Bench\Stub\ExampleRequestDTO;
12+
use TypeLang\Mapper\Runtime\ClassInstantiator\ReflectionClassInstantiator;
13+
14+
#[Revs(50), Warmup(5), Iterations(20), BeforeMethods('prepare')]
15+
final class ReflectionInstantiatorBench extends InstantiatorBenchmark
16+
{
17+
private readonly ReflectionClassInstantiator $instantiator;
18+
19+
public function prepare(): void
20+
{
21+
$this->instantiator = new ReflectionClassInstantiator();
22+
}
23+
24+
public function benchInstantiate(): void
25+
{
26+
$this->instantiator->instantiate(ExampleRequestDTO::class);
27+
}
28+
}

bench/src/JMSAttributesBench.php renamed to bench/src/Serializers/JMSAttributesBench.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace TypeLang\Mapper\Bench;
5+
namespace TypeLang\Mapper\Bench\Serializers;
66

77
use JMS\Serializer\Serializer;
88
use JMS\Serializer\SerializerBuilder;
@@ -13,7 +13,7 @@
1313
use PhpBench\Attributes\Warmup;
1414
use TypeLang\Mapper\Bench\Stub\ExampleRequestDTO;
1515

16-
#[Revs(20), Warmup(5), Iterations(20), BeforeMethods('prepare')]
16+
#[Revs(30), Warmup(3), Iterations(5), BeforeMethods('prepare')]
1717
final class JMSAttributesBench extends MapperBenchmark
1818
{
1919
private readonly Serializer $raw;
@@ -37,7 +37,7 @@ public function prepare(): void
3737
->addDefaultHandlers()
3838
->addDefaultDeserializationVisitors()
3939
->addDefaultSerializationVisitors()
40-
->setCacheDir(__DIR__ . '/../var')
40+
->setCacheDir(__DIR__ . '/../../var')
4141
->setMetadataCache(new PsrCacheAdapter('jms', $this->psr6))
4242
->build();
4343
}

bench/src/MapperBenchmark.php renamed to bench/src/Serializers/MapperBenchmark.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace TypeLang\Mapper\Bench;
5+
namespace TypeLang\Mapper\Bench\Serializers;
66

77
use Psr\Cache\CacheItemPoolInterface;
88
use Psr\SimpleCache\CacheInterface;
@@ -44,7 +44,7 @@ protected function prepare(): void
4444
{
4545
$this->psr6 = new FilesystemAdapter(
4646
namespace: 'benchmarks',
47-
directory: __DIR__ . '/../var',
47+
directory: __DIR__ . '/../../var',
4848
);
4949

5050
$this->psr16 = new Psr16Cache(

bench/src/SymfonyDocBlockBench.php renamed to bench/src/Serializers/SymfonyDocBlockBench.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace TypeLang\Mapper\Bench;
5+
namespace TypeLang\Mapper\Bench\Serializers;
66

77
use PhpBench\Attributes\BeforeMethods;
88
use PhpBench\Attributes\Iterations;
@@ -17,7 +17,7 @@
1717
use Symfony\Component\Serializer\Serializer;
1818
use TypeLang\Mapper\Bench\Stub\ExampleRequestDTO;
1919

20-
#[Revs(20), Warmup(5), Iterations(20), BeforeMethods('prepare')]
20+
#[Revs(30), Warmup(3), Iterations(5), BeforeMethods('prepare')]
2121
final class SymfonyDocBlockBench extends MapperBenchmark
2222
{
2323
private readonly Serializer $raw;

0 commit comments

Comments
 (0)