Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Catastrophic backtracking in JSDoc param types #495

Closed

Description

@winstliu

Prerequisites

Description

There is currently catastrophic backtracking occurring when we we fail to match the param type when multiple are present in JSDoc comments.

/**
 * @param {String|String|String|String|String|String|String|String*} test 
 */

should be enough to reproduce. Another example is

/**
 * @param {PIXI.DisplayObject|PIXI.Container|PIXI.BaseTexture|PIXI.Texture|PIXI.Graphic*} item - Object to
 *        add to the queue

Thanks to @andrewstart for reporting.

Steps to Reproduce

  1. Copy/paste one of the two snippets into a new editor and set the syntax to JavaScript

Expected behavior: Instant highlighting

Actual behavior: Keep Waiting dialog

Reproduces how often: 100%

Versions

[email protected], but it's been happening since at least 0.122.0.

/cc @bgriffith @Alhadis

Activity

  1. Alhadis commented on Feb 28, 2017

    @Alhadis
    Contributor

    Sigh... I'll get this one (again).

  2. Alhadis commented on Feb 28, 2017

    @Alhadis
    Contributor

    FYI, the entire reason for these performance issues - and the ridiculously-contrived expressions causing them - is that nobody's bothered to structure these grammars properly.

    The size of the JSDoc patterns alone suggests it's worth assigning its own grammar.

  3. winstliu commented on Feb 28, 2017

    @winstliu
    ContributorAuthor

    Yeah. The JSDoc section definitely needs to be restructured and yanked out to become its own grammar (it's just been pretty low priority, because, well, it worked). It's fairly impossible to see where the backtracking is occurring unlike the last one.

    (Also, commas will trigger the catastrophic backtracking as well)

  4. Alhadis commented on Feb 28, 2017

    @Alhadis
    Contributor

    If I do a full rewrite, will it be worth it though?

    I mean, the whole tree-sitter thing and all...

  5. winstliu commented on Feb 28, 2017

    @winstliu
    ContributorAuthor

    That's up to you.

  6. Alhadis commented on Feb 28, 2017

    @Alhadis
    Contributor

    I'll do it to make up for the unsuccessful SassLess->CSS integration... which, BTW, will have to be limited to some unexciting pattern inclusions. I was hoping of having them share CSS's pattern-matching, but having to accommodate subtraction arithmetic between words has killed it.

    This took too long because I wanted to do too much. :c

  7. winstliu commented on Feb 28, 2017

    @winstliu
    ContributorAuthor

    A good first step to take is to make the capture on L2240 possessive. That gets rid of the catastrophic bactrack error on Regex101 (back to ~1-3ms), but there's some other pattern still backtracking in Atom.

  8. Alhadis commented on Feb 28, 2017

    @Alhadis
    Contributor

    Think I'll just rewrite the whole damn JSDoc grammar myself. How's that for possessive? 💚

    Shouldn't take me more than an hour. The "language" has such an absurdly-simple composition, it's embarrassing that it could snowball into what it has... :(

  9. Alhadis commented on Feb 28, 2017

    @Alhadis
    Contributor

    I'll start once I've finished fixing file-icons/atom#550... Forget it, attacking now.

  10. Alhadis commented on Feb 28, 2017

    @Alhadis
    Contributor

    @50Wliu JSYK, I've tweaked the scope-names for the /* … */ blocks; they're technically not entirely accurate going by @infininight's guidelines for punctuation-type scopes (which are the closest thing we have to an authority on the topic).

    If you see similar changes in future pull-requests, my recent discovery of that gist will be the reason why.

  11. Alhadis commented on Feb 28, 2017

    @Alhadis
    Contributor

    @50Wliu Can I ditch other.meta.jsdoc in favour of something, erh, specific? Or do you foresee changes to these scopes breaking any documentation-related Atom packages or anything?

  12. winstliu commented on Feb 28, 2017

    @winstliu
    ContributorAuthor

    Can't tell you without seeing the PR first, but that does sound like a weird scope.

  13. Alhadis commented on Feb 28, 2017

    @Alhadis
    Contributor

    Well... to be honest, many of these scopes are weird. I'm keeping them for theming compatibility, but any scope that contains other starts looking like deleteme very rapidly.

    I'll torch it. Not gonna keep cargo-culted material.

  14. Alhadis commented on Feb 28, 2017

    @Alhadis
    Contributor

    Shouldn't take me more than an hour

    Okay, ignore that, because I'm spending more time reading about JSDoc features I didn't know existed than I am writing stuff (so far). I'm combing through the official specification alphabetically, writing the grammar as I go along (I'm also aware of Google Closure Compiler syntax and TypoScript flavours too, so I'l tackle those too).

    You can track my progress here.

  15. Alhadis commented on Mar 3, 2017

    @Alhadis
    Contributor

    ... just letting you know I'm done, but I'm damned if I know how long it'll take to repair these specs. Heh.

    Shouldn't take an hour...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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