Skip to content

Any ideas on how we could speed up ResourceClassResolver? #1068

@soyuka

Description

@soyuka

This class gets called a lot. I already speed up things by ~20% by avoiding the resourceNameCollectionFactory->create() call (quick & dirty):

    public function isResourceClass(string $type): bool
    {
        if (isset($this->arrayCache[$type])) {
            return $this->arrayCache[$type];
        }

        foreach ($this->resourceNameCollectionFactory->create() as $resourceClass) {
            $this->arrayCache[$resourceClass] = true;
            if ($type === $resourceClass) {
                return true;
            }
        }

        $this->arrayCache[$type] = false;
        return false;
    }

Though, getResourceClass is still slow \o/. I'm not sure that we can find any key to cache our $value though.
I think that by removing try/catch we could improve it a bit, but this would break a lot of things (returning null instead of throwing an InvalidArgumentException). WDYT?

Any ideas appreciated!

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions