Skip to content

Conversation

tanishiking
Copy link
Contributor

@tanishiking tanishiking commented Mar 21, 2022

As a first step for fixing #6844, this PR suppress the sbt server from sending build/publishDiagnostics if

  • there were no problems with the previous build &&
  • there are no problems with the current build

While bloop doesn't send notifications if problems are the same as the previous ones, I have a concern about comparing all the problems may slow down the server performance a bit (Is there a good way to profile build?)
Therefore, this PR suppresses the diagnostics only when there are (and were) no problems, for the time being. (I believe this is still pretty effective for reducing the message load between BSP client-server, assuming most of the programs have no problems).

example

For example, when we edit a file in this repository, (after a full compilation, edit doesn't contain any problems) sbt BSP sends the following requests/notifications

sbt 1.6.2
[Trace - 09:46:34 PM] Sending request 'buildTarget/compile - (11)'
Params: {
  "targets": [
    {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  ]
}


[Trace - 09:46:35 PM] Received notification 'build/logMessage'
Params: {
  "type": 4,
  "message": "Processing buildTarget/compile"
}


[Trace - 09:46:35 PM] Received notification 'build/taskStart'
Params: {
  "taskId": {
    "id": "24",
    "parents": []
  },
  "eventTime": 1647866795052,
  "message": "Compiling proj1",
  "dataKind": "compile-task",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj1/Compile"
    }
  }
}


[Trace - 09:46:35 PM] Received notification 'build/publishDiagnostics'
Params: {
  "textDocument": {
    "uri": "file:///Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/proj1/src/main/scala/A.scala"
  },
  "buildTarget": {
    "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj1/Compile"
  },
  "diagnostics": [],
  "reset": true
}


[Trace - 09:46:35 PM] Received notification 'build/taskFinish'
Params: {
  "taskId": {
    "id": "24",
    "parents": []
  },
  "eventTime": 1647866795057,
  "message": "Compiled proj1",
  "status": 1,
  "dataKind": "compile-report",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj1/Compile"
    },
    "errors": 0,
    "warnings": 0,
    "time": 5
  }
}


[Trace - 09:46:35 PM] Received notification 'build/taskStart'
Params: {
  "taskId": {
    "id": "25",
    "parents": []
  },
  "eventTime": 1647866795061,
  "message": "Compiling proj2",
  "dataKind": "compile-task",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:46:35 PM] Received notification 'build/logMessage'
Params: {
  "type": 3,
  "message": "compiling 1 Scala source to /Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/proj2/target/scala-2.12/classes ..."
}


[Trace - 09:46:35 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "25",
    "parents": []
  },
  "eventTime": 1647866795204,
  "message": "Compiling proj2 (10%)",
  "total": 28,
  "progress": 10,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:46:35 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "25",
    "parents": []
  },
  "eventTime": 1647866795204,
  "message": "Compiling proj2 (10%)",
  "total": 28,
  "progress": 10,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:46:35 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "25",
    "parents": []
  },
  "eventTime": 1647866795707,
  "message": "Compiling proj2 (25%)",
  "total": 28,
  "progress": 25,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:46:35 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "25",
    "parents": []
  },
  "eventTime": 1647866795707,
  "message": "Compiling proj2 (25%)",
  "total": 28,
  "progress": 25,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:46:35 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "25",
    "parents": []
  },
  "eventTime": 1647866795718,
  "message": "Compiling proj2 (35%)",
  "total": 28,
  "progress": 35,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:46:35 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "25",
    "parents": []
  },
  "eventTime": 1647866795719,
  "message": "Compiling proj2 (35%)",
  "total": 28,
  "progress": 35,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:46:35 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "25",
    "parents": []
  },
  "eventTime": 1647866795737,
  "message": "Compiling proj2 (50%)",
  "total": 28,
  "progress": 50,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:46:35 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "25",
    "parents": []
  },
  "eventTime": 1647866795737,
  "message": "Compiling proj2 (50%)",
  "total": 28,
  "progress": 50,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:46:35 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "25",
    "parents": []
  },
  "eventTime": 1647866795848,
  "message": "Compiling proj2 (60%)",
  "total": 28,
  "progress": 60,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:46:35 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "25",
    "parents": []
  },
  "eventTime": 1647866795849,
  "message": "Compiling proj2 (60%)",
  "total": 28,
  "progress": 60,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:46:35 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "25",
    "parents": []
  },
  "eventTime": 1647866795858,
  "message": "Compiling proj2 (75%)",
  "total": 28,
  "progress": 75,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:46:35 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "25",
    "parents": []
  },
  "eventTime": 1647866795859,
  "message": "Compiling proj2 (75%)",
  "total": 28,
  "progress": 75,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:46:35 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "25",
    "parents": []
  },
  "eventTime": 1647866795860,
  "message": "Compiling proj2 (85%)",
  "total": 28,
  "progress": 85,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:46:35 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "25",
    "parents": []
  },
  "eventTime": 1647866795860,
  "message": "Compiling proj2 (85%)",
  "total": 28,
  "progress": 85,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:46:35 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "25",
    "parents": []
  },
  "eventTime": 1647866795896,
  "message": "Compiling proj2 (100%)",
  "total": 28,
  "progress": 100,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:46:35 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "25",
    "parents": []
  },
  "eventTime": 1647866795896,
  "message": "Compiling proj2 (100%)",
  "total": 28,
  "progress": 100,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:46:35 PM] Received notification 'build/logMessage'
Params: {
  "type": 3,
  "message": "done compiling"
}


[Trace - 09:46:35 PM] Received notification 'build/publishDiagnostics'
Params: {
  "textDocument": {
    "uri": "file:///Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/proj2/src/main/scala/B.scala"
  },
  "buildTarget": {
    "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
  },
  "diagnostics": [],
  "reset": true
}


[Trace - 09:46:35 PM] Received notification 'build/publishDiagnostics'
Params: {
  "textDocument": {
    "uri": "file:///Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/proj2/src/main/scala/C.scala"
  },
  "buildTarget": {
    "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
  },
  "diagnostics": [],
  "reset": true
}


[Trace - 09:46:35 PM] Received notification 'build/taskFinish'
Params: {
  "taskId": {
    "id": "25",
    "parents": []
  },
  "eventTime": 1647866795903,
  "message": "Compiled proj2",
  "status": 1,
  "dataKind": "compile-report",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    },
    "errors": 0,
    "warnings": 0,
    "time": 842
  }
}


[Trace - 09:46:35 PM] Received response 'buildTarget/compile - (11)' in 912ms
Result: {
  "statusCode": 1
}
Error: null


[Trace - 09:46:35 PM] Sending request 'buildTarget/scalaMainClasses - (12)'
Params: {
  "targets": [
    {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  ]
}


[Trace - 09:46:35 PM] Sending request 'buildTarget/scalaTestClasses - (13)'
Params: {
  "targets": [
    {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  ]
}


[Trace - 09:46:35 PM] Received notification 'build/logMessage'
Params: {
  "type": 4,
  "message": "Processing buildTarget/scalaMainClasses"
}


[Trace - 09:46:35 PM] Received notification 'build/taskStart'
Params: {
  "taskId": {
    "id": "26",
    "parents": []
  },
  "eventTime": 1647866795950,
  "message": "Compiling proj1",
  "dataKind": "compile-task",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj1/Compile"
    }
  }
}


[Trace - 09:46:35 PM] Received notification 'build/publishDiagnostics'
Params: {
  "textDocument": {
    "uri": "file:///Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/proj1/src/main/scala/A.scala"
  },
  "buildTarget": {
    "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj1/Compile"
  },
  "diagnostics": [],
  "reset": true
}


[Trace - 09:46:35 PM] Received notification 'build/taskFinish'
Params: {
  "taskId": {
    "id": "26",
    "parents": []
  },
  "eventTime": 1647866795956,
  "message": "Compiled proj1",
  "status": 1,
  "dataKind": "compile-report",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj1/Compile"
    },
    "errors": 0,
    "warnings": 0,
    "time": 6
  }
}


[Trace - 09:46:35 PM] Received notification 'build/taskStart'
Params: {
  "taskId": {
    "id": "27",
    "parents": []
  },
  "eventTime": 1647866795959,
  "message": "Compiling proj2",
  "dataKind": "compile-task",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:46:35 PM] Received notification 'build/publishDiagnostics'
Params: {
  "textDocument": {
    "uri": "file:///Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/proj2/src/main/scala/B.scala"
  },
  "buildTarget": {
    "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
  },
  "diagnostics": [],
  "reset": true
}


[Trace - 09:46:35 PM] Received notification 'build/publishDiagnostics'
Params: {
  "textDocument": {
    "uri": "file:///Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/proj2/src/main/scala/C.scala"
  },
  "buildTarget": {
    "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
  },
  "diagnostics": [],
  "reset": true
}


[Trace - 09:46:35 PM] Received notification 'build/taskFinish'
Params: {
  "taskId": {
    "id": "27",
    "parents": []
  },
  "eventTime": 1647866795966,
  "message": "Compiled proj2",
  "status": 1,
  "dataKind": "compile-report",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    },
    "errors": 0,
    "warnings": 0,
    "time": 7
  }
}


[Trace - 09:46:35 PM] Received response 'buildTarget/scalaMainClasses - (12)' in 60ms
Result: {
  "items": [
    {
      "target": {
        "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
      },
      "classes": []
    }
  ]
}
Error: null


[Trace - 09:46:35 PM] Received notification 'build/logMessage'
Params: {
  "type": 4,
  "message": "Processing buildTarget/scalaTestClasses"
}


[Trace - 09:46:35 PM] Received response 'buildTarget/scalaTestClasses - (13)' in 83ms
Result: {
  "items": [
    {
      "target": {
        "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
      },
      "classes": []
    }
  ]
}
Error: null
this SNAPSHOT

[Trace - 09:52:06 PM] Sending request 'buildTarget/compile - (14)'
Params: {
  "targets": [
    {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  ]
}


[Trace - 09:52:06 PM] Received notification 'build/logMessage'
Params: {
  "type": 4,
  "message": "Processing buildTarget/compile"
}


[Trace - 09:52:06 PM] Received notification 'build/taskStart'
Params: {
  "taskId": {
    "id": "28",
    "parents": []
  },
  "eventTime": 1647867126276,
  "message": "Compiling proj1",
  "dataKind": "compile-task",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj1/Compile"
    }
  }
}


[Trace - 09:52:06 PM] Received notification 'build/taskFinish'
Params: {
  "taskId": {
    "id": "28",
    "parents": []
  },
  "eventTime": 1647867126281,
  "message": "Compiled proj1",
  "status": 1,
  "dataKind": "compile-report",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj1/Compile"
    },
    "errors": 0,
    "warnings": 0,
    "time": 5
  }
}


[Trace - 09:52:06 PM] Received notification 'build/taskStart'
Params: {
  "taskId": {
    "id": "29",
    "parents": []
  },
  "eventTime": 1647867126287,
  "message": "Compiling proj2",
  "dataKind": "compile-task",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:52:06 PM] Received notification 'build/logMessage'
Params: {
  "type": 3,
  "message": "compiling 1 Scala source to /Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/proj2/target/scala-2.12/classes ..."
}


[Trace - 09:52:08 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "29",
    "parents": []
  },
  "eventTime": 1647867128167,
  "message": "Compiling proj2 (10%)",
  "total": 28,
  "progress": 10,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:52:08 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "29",
    "parents": []
  },
  "eventTime": 1647867128170,
  "message": "Compiling proj2 (10%)",
  "total": 28,
  "progress": 10,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:52:08 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "29",
    "parents": []
  },
  "eventTime": 1647867128945,
  "message": "Compiling proj2 (25%)",
  "total": 28,
  "progress": 25,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:52:08 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "29",
    "parents": []
  },
  "eventTime": 1647867128945,
  "message": "Compiling proj2 (25%)",
  "total": 28,
  "progress": 25,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:52:09 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "29",
    "parents": []
  },
  "eventTime": 1647867129043,
  "message": "Compiling proj2 (35%)",
  "total": 28,
  "progress": 35,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:52:09 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "29",
    "parents": []
  },
  "eventTime": 1647867129048,
  "message": "Compiling proj2 (35%)",
  "total": 28,
  "progress": 35,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:52:09 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "29",
    "parents": []
  },
  "eventTime": 1647867129398,
  "message": "Compiling proj2 (50%)",
  "total": 28,
  "progress": 50,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:52:09 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "29",
    "parents": []
  },
  "eventTime": 1647867129398,
  "message": "Compiling proj2 (50%)",
  "total": 28,
  "progress": 50,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:52:09 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "29",
    "parents": []
  },
  "eventTime": 1647867129843,
  "message": "Compiling proj2 (60%)",
  "total": 28,
  "progress": 60,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:52:09 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "29",
    "parents": []
  },
  "eventTime": 1647867129844,
  "message": "Compiling proj2 (60%)",
  "total": 28,
  "progress": 60,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:52:09 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "29",
    "parents": []
  },
  "eventTime": 1647867129901,
  "message": "Compiling proj2 (75%)",
  "total": 28,
  "progress": 75,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:52:09 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "29",
    "parents": []
  },
  "eventTime": 1647867129901,
  "message": "Compiling proj2 (75%)",
  "total": 28,
  "progress": 75,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:52:09 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "29",
    "parents": []
  },
  "eventTime": 1647867129913,
  "message": "Compiling proj2 (85%)",
  "total": 28,
  "progress": 85,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:52:09 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "29",
    "parents": []
  },
  "eventTime": 1647867129913,
  "message": "Compiling proj2 (85%)",
  "total": 28,
  "progress": 85,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:52:10 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "29",
    "parents": []
  },
  "eventTime": 1647867130068,
  "message": "Compiling proj2 (100%)",
  "total": 28,
  "progress": 100,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:52:10 PM] Received notification 'build/taskProgress'
Params: {
  "taskId": {
    "id": "29",
    "parents": []
  },
  "eventTime": 1647867130069,
  "message": "Compiling proj2 (100%)",
  "total": 28,
  "progress": 100,
  "dataKind": "compile-progress",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:52:10 PM] Received notification 'build/logMessage'
Params: {
  "type": 3,
  "message": "done compiling"
}


[Trace - 09:52:10 PM] Received notification 'build/taskFinish'
Params: {
  "taskId": {
    "id": "29",
    "parents": []
  },
  "eventTime": 1647867130082,
  "message": "Compiled proj2",
  "status": 1,
  "dataKind": "compile-report",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    },
    "errors": 0,
    "warnings": 0,
    "time": 3795
  }
}


[Trace - 09:52:10 PM] Received response 'buildTarget/compile - (14)' in 3914ms
Result: {
  "statusCode": 1
}
Error: null


[Trace - 09:52:10 PM] Sending request 'buildTarget/scalaMainClasses - (15)'
Params: {
  "targets": [
    {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  ]
}


[Trace - 09:52:10 PM] Sending request 'buildTarget/scalaTestClasses - (16)'
Params: {
  "targets": [
    {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  ]
}


[Trace - 09:52:10 PM] Received notification 'build/logMessage'
Params: {
  "type": 4,
  "message": "Processing buildTarget/scalaMainClasses"
}


[Trace - 09:52:10 PM] Received notification 'build/taskStart'
Params: {
  "taskId": {
    "id": "30",
    "parents": []
  },
  "eventTime": 1647867130194,
  "message": "Compiling proj1",
  "dataKind": "compile-task",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj1/Compile"
    }
  }
}


[Trace - 09:52:10 PM] Received notification 'build/taskFinish'
Params: {
  "taskId": {
    "id": "30",
    "parents": []
  },
  "eventTime": 1647867130199,
  "message": "Compiled proj1",
  "status": 1,
  "dataKind": "compile-report",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj1/Compile"
    },
    "errors": 0,
    "warnings": 0,
    "time": 5
  }
}


[Trace - 09:52:10 PM] Received notification 'build/taskStart'
Params: {
  "taskId": {
    "id": "31",
    "parents": []
  },
  "eventTime": 1647867130206,
  "message": "Compiling proj2",
  "dataKind": "compile-task",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    }
  }
}


[Trace - 09:52:10 PM] Received notification 'build/taskFinish'
Params: {
  "taskId": {
    "id": "31",
    "parents": []
  },
  "eventTime": 1647867130214,
  "message": "Compiled proj2",
  "status": 1,
  "dataKind": "compile-report",
  "data": {
    "target": {
      "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
    },
    "errors": 0,
    "warnings": 0,
    "time": 8
  }
}


[Trace - 09:52:10 PM] Received response 'buildTarget/scalaMainClasses - (15)' in 70ms
Result: {
  "items": [
    {
      "target": {
        "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
      },
      "classes": []
    }
  ]
}
Error: null


[Trace - 09:52:10 PM] Received notification 'build/logMessage'
Params: {
  "type": 4,
  "message": "Processing buildTarget/scalaTestClasses"
}


[Trace - 09:52:10 PM] Received response 'buildTarget/scalaTestClasses - (16)' in 97ms
Result: {
  "items": [
    {
      "target": {
        "uri": "file:/Users/tanishiking/src/github.com/tanishiking/sbt-multi-project/#proj2/Compile"
      },
      "classes": []
    }
  ]
}
Error: null

Point is, there's no publishDiagnostics notifications anymore :)

@tanishiking tanishiking changed the title Do not fire build/publishDiagnostics if there are (and were) no problems [BSP]Do not fire build/publishDiagnostics if there are (and were) no problems Mar 21, 2022
@@ -2310,10 +2310,11 @@ object Defaults extends BuildCommon {
val ci = (compile / compileInputs).value
val ping = earlyOutputPing.value
val reporter = (compile / bspReporter).value
val prevAnalysis = previousCompile.value.analysis.toOption.getOrElse(Analysis.empty)
Copy link
Contributor Author

@tanishiking tanishiking Mar 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm bit concerned about the compile performance degradation by depending on previousCompile in compileIncrementalTask 🤔

@tanishiking
Copy link
Contributor Author

tanishiking commented Mar 25, 2022

Here's a rough observation from this improvement.
The graph (of VisualVM) below depicts the CPU usage of Metals Server (with sbt BSP), on my Laptop, and opens random files in /metals of scalameta/metals.

  • MacBook Pro (16-inch, 2019)
  • Processor: 2.6 GHz 6-Core Intel Core i7
  • Memory: 16 GB 2667 MHz DDR4

sbt 1.6.2

Screen Shot 2022-03-25 at 17 31 41

  • We can see a lot of small spikes and all of them happen when I open a file in VSCode (metals).
  • When we open a new file, metals request build/compile on the project, and sbt sends back a ton of build/publishDiagnostics notifications to metals (even though there's no change from the previous compile).
  • When Metals receives the build/publishDiagnostics, it transforms the data and sends a notification to VSCode via LSP, which consumes some CPU power.
  • Each spike consume around 10-15% of CPU.

This build

Screen Shot 2022-03-25 at 18 56 21

  • Still, we can see a lot of spikes, and they're caused by opening a file in metals.
  • However, now sbt doesn't send a notification if there's no change in problem (and there's no problem) with the previous compile, and a number of build/publishDiagnostics are much smaller (like 200-500 -> a few).
  • Each spike consumes around 5% of CPU.

Copy link
Member

@eed3si9n eed3si9n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@asflierl
Copy link
Contributor

asflierl commented May 13, 2022

@tanishiking I tried this with SBT 1.7.0-M2 today on a very minimal scala 3 project with Metals 0.11.5 in VSCode and SBT as BSP backend and it looks like once I introduce a compile error and then remove it again, Metals is no longer notified that the error is gone, i.e. it stays in the "problems" list and will not go away anymore.
The only way to get it to disappear is to introduce an error in another sourcefile... but then of course that one will stay even after it's fixed.
(side note: if I do the same with SBT 1.6.2, everything works fine and as expected - so I was assuming this PR might be involved)

@eed3si9n
Copy link
Member

@asflierl That sounds important. Could you escalate it as a GitHub issue please? Thanks!

@tanishiking
Copy link
Contributor Author

@asflierl Thank you for reporting!
Could you give me a minimal setup and procedure to reproduce it? In my environment (sbt 1.7.0-M2, Metals 0.11.5, VSCode and sbt as BSP), everything works fine.

@kpodsiad
Copy link
Contributor

I tried to fix this problem and I found root cause. Depending on previous compilation result isn't working because when project has some error, getReportedProblems returns an empty Array. So we'll end up in situation that there were no problems and currently there are no problems so diagnostics don't need to be published.

However, when there are some warnings in the project, getReportedProblems will contain these ones. I'm not sure why problems contain only warnings. If there are some errors in project, previous CompileAnalysis isn't updated?

@adpi2
Copy link
Member

adpi2 commented Jun 16, 2022

However, when there are some warnings in the project, getReportedProblems will contain these ones. I'm not sure why problems contain only warnings. If there are some errors in project, previous CompileAnalysis isn't updated?

Yes I think you are right @kpodsiad, the previousCompile is the latest compile that succeeded. If the compile task fails, it throws an error and it is not stored into the previousCompile. So basically the errors of a failed compilation are lost. But maybe we could store them in the BuildServerReporter itself?

@kpodsiad
Copy link
Contributor

Thanks for clarification @adpi2!

If the compile task fails, it throws an error and it is not stored into the previousCompile

I tried to search where compilation analysis is stored in case of successful compilations but I couldn't find it. Do you mind pointing it out?

But maybe we could store them in the BuildServerReporter itself?

I was thinking about that, for now even the simplest hasAnyErrors: Map[Path, Boolean] would be sufficient. However, I wonder how big memory impact this can have on very large projects which have, lets say, thousands of files 🤔

I did some estimation (gist here) and such map (either mutable.Map or ConcurrentHashMap) would have roughly 96MB, is this memory footprint acceptable?

I also experimented with some variants:

  • Map[Path, Int] has 112MB
  • Set[Path] has 88MB (now I realized that Map[Path, Boolean] is an equivalent of this version 🤦 )

Unless you have better idea I'll try with Set[Path] approach first.

@adpi2
Copy link
Member

adpi2 commented Jun 16, 2022

I tried to search where compilation analysis is stored in case of successful compilations but I couldn't find it. Do you mind pointing it out?

Here it is:

val analysisResult: CompileResult = compileIncremental.value
val exportP = exportPipelining.value
// Save analysis midway if pipelining is enabled
if (analysisResult.hasModified && exportP) {
val store =
MixedAnalyzingCompiler.staticCachedStore(setup.cacheFile.toPath, !useBinary)
val contents = AnalysisContents.create(analysisResult.analysis(), analysisResult.setup())
store.set(contents)
// this stores the eary analysis (again) in case the subproject contains a macro
setup.earlyAnalysisStore.toOption map { earlyStore =>
earlyStore.set(contents)
}
}

Unless you have better idea I'll try with Set[Path] approach first.

Seems like a good approach to me. I guess it is better in term of performance to store the file with errors because we want the case with no errors to be as fast as possible.

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

Successfully merging this pull request may close these issues.

5 participants