Skip to content

Conversation

@jtkiesel
Copy link
Contributor

@jtkiesel jtkiesel commented Sep 8, 2025

What changed with this PR:

Our call helper is implemented by calling AstPath's map method and indexing into the returned array. This PR removes the ability to index to anything other than 0, to prevent it from being used to execute individual calls to individual path indices, which was causing all indices to be re-processed each time call was executed, which in some cases (such as long if-else statement chains) was causing printer functions to be executed an exponential number of times (according to the number of if-else statements in the chain). Anything that was previously using the indexing feature of call is now updated to either use the map helper once, and index into the results, or use AstPath.call directly, which is a bit more verbose, but it's a rare use-case in our printer to begin with.

Example

Input

class Example {

  void example() {
    if (1) {
      // 1
    } else if (2) {
      // 2
    } else if (3) {
      // 3
    } else if (4) {
      // 4
    } else if (5) {
      // 5
    } else if (6) {
      // 6
    } else if (7) {
      // 7
    } else if (8) {
      // 8
    } else if (9) {
      // 9
    } else if (10) {
      // 10
    } else if (11) {
      // 11
    } else if (12) {
      // 12
    } else if (13) {
      // 13
    } else if (14) {
      // 14
    } else if (15) {
      // 15
    } else if (16) {
      // 16
    } else if (17) {
      // 17
    } else if (18) {
      // 18
    } else if (19) {
      // 19
    } else if (20) {
      // 20
    }
  }
}

Output

The same, but it no longer takes an exponential amount of time to print.

Relative issues or prs:

Closes #757

@jtkiesel jtkiesel merged commit 6935bd8 into jhipster:main Sep 8, 2025
6 checks passed
@jtkiesel jtkiesel deleted the fix/long-if-else-chain-performance branch September 8, 2025 04:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for handling long if/else chains

1 participant