Skip to content

Single step expression is compiled into regex more than once (thus it makes test execution slower) #2035

Closed
@maio

Description

@maio

It seems that all step expressions are re-compiled into regexes before each scenario.

Steps to reproduce the behavior:

  1. Given I have feature file like:
Feature: Whatever

Scenario: S1
  Given foo

Scenario: S2
  Given foo
  1. and I implement foo step e.g.
@Given("foo")
public void foo() {}
  1. When I execute the feature file
  2. Then io.cucumber.core.stepexpression.StepExpressionFactory.createExpression method is executed twice with "foo" expression (because there are two scenarios)
  3. therefore "foo" is compiled into regex twice

Expected behavior

"foo" is compiled only once.

Context & Motivation

I noticed that if I remove all bodies of my steps from sources it still takes considerable amount of time to run my tests (e.g., 2.2 seconds for 186 scenarios). Using Java Flight Recorder I collected some profiling data and it seems that a lot of time is being spent in io.cucumber.core.stepexpression.StepExpressionFactory.createExpression (47% in my case according to flame graph - see below). When I examined that method in debugger I noticed that it's being called more than once with same expressionString parameter.

Screenshots

image

Your Environment

  • Versions used 6.1.2
  • Linux, Gradle, Kotlin

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐛 bugDefect / Bug✅ acceptedThe core team has agreed that it is a good idea to fix this

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions