Skip to content

endsInKeyword check slow on large Javascript #139

@mdetrano

Description

@mdetrano

I noticed something in the endsInKeyword function that I think is causing a large performance hit when processing large amounts of Javascript.

The check does a preg_match on the full output in order to see if it is ending with certain keywords. However, as that output grows this check takes longer and longer to run.

Would it not be better to limit the amount of output matched to something reasonable? For instance, I changed:

$testOutput = $this->output . $this->a;

to

$testOutput = substr($this->output . $this->a, -50);

and processing time for my experiment dropped from over a minute to a second or two. No change in the Javascript produced (though I am not entirely sure what condition this function is used for).

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