Skip to content

Huge delay running task with nikic/PHP-Parser instance in parallel #815

Closed
@InvisibleSmiley

Description

@InvisibleSmiley
Q A
Version 0.22.0
Bug? yes
OS Windows 10

Note: I'm not sure whether this is a bug with nikic/PHP-Parser or GrumPHP but it's hard to tell for me since I don't know how to debug parallel mode.

A task that keeps an instance of nikic/PHP-Parser (without actively using it!) takes much longer to complete in parallel mode.
Git commit

  • finishes instantly with parallel: false
  • takes ~4sec with parallel: true and Xdebug disabled
  • takes ~20sec with parallel: true and Xdebug enabled

Steps to reproduce:

# create/fill grumphp.yml
# create/fill composer.json
mkdir src
# create/fill src/ParserStub.php
composer install
git init
git commit

grumphp.yml:

grumphp:
    tasks:
      parserstub:
    parallel:
      enabled: true

services:
    task.ParserStub:
        class: Foo\GrumPHP\Task\ParserStub
        arguments:
            - '@process_builder'
            - '@formatter.raw_process'
        tags:
            - {name: grumphp.task, task: parserstub}

composer.json:

{
    "name": "foo/parserstub",
    "require-dev": {
        "nikic/php-parser": "^4.9",
        "phpro/grumphp": "^0.22.0"
    },
    "autoload-dev": {
        "psr-4": {
            "Foo\\GrumPHP\\Task\\": "src/"
        }
    }
}

src/ParserStub.php:

<?php
declare(strict_types=1);

namespace Foo\GrumPHP\Task;

use GrumPHP\Formatter\ProcessFormatterInterface;
use GrumPHP\Process\ProcessBuilder;
use GrumPHP\Runner\TaskResult;
use GrumPHP\Runner\TaskResultInterface;
use GrumPHP\Task\AbstractExternalTask;
use GrumPHP\Task\Context\ContextInterface;
use GrumPHP\Task\Context\GitPreCommitContext;
use PhpParser\Lexer;
use PhpParser\Parser\Php7;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class ParserStub extends AbstractExternalTask
{
    private $parser;

    public function __construct(
        ProcessBuilder $processBuilder,
        ProcessFormatterInterface $formatter
    ) {
        parent::__construct($processBuilder, $formatter);
        $this->parser = new Php7(new Lexer());
    }

    public static function getConfigurableOptions(): OptionsResolver
    {
        return new OptionsResolver();
    }

    public function canRunInContext(ContextInterface $context): bool
    {
        return $context instanceof GitPreCommitContext;
    }

    public function run(ContextInterface $context): TaskResultInterface
    {
        return TaskResult::createPassed($this, $context);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions