Skip to content

Refactorings in preparation for parallel visualization execution #13354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Jun 30, 2025

Conversation

hubertp
Copy link
Collaborator

@hubertp hubertp commented Jun 24, 2025

Pull Request Description

Work on reactive observers for visualizations revealed a number of blockers once one attempts to execute visualizations in parallel. This PR extracts the less controversial parts that became obvious once we opened a pandora's box, as well as a number of startup improvements:

  • push context request does not trigger execution by default (it typically lacks IdMap necessary for instrumentation at that stage)
  • split context lock to read/write one to reduce lock contention and ensure correctness
  • changing methods on ExecutionService to not block
  • make HostClassLoader thread-safe
  • reduce write compilation lock contention by first attempting to evaluate an expression with a read lock only
  • fixed a bug that potentially invalidates visualizations' state too often

Important Notes

Should be easier to review than #13219 that went through a number of experiments.
Some startup improvements should be visible from this change already as we reduce lock contention.

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • All code follows the
    Scala,
    Java,
    TypeScript,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.

hubertp added 20 commits June 23, 2025 13:00
Reduce lock contention by splitting context lock into a read/write one.
Context lock has been slowly ignored in various jobs in favour of
improved performance. It shouldn't be, as most of the time we only need
a read context lock.
By default, no execution is triggered by push context request.
Most of `ExecutionService` now returns Futures that can be easier to
compose and execute via threadpools.
When diagnostics are being gathered outside of ThreadManager, execution
will blow up due to Truffle restrictions.
Should reduce lock contention on startup.
@hubertp hubertp added the CI: No changelog needed Do not require a changelog entry for this PR. label Jun 24, 2025
Copy link
Contributor

@GregoryTravis GregoryTravis left a comment

Choose a reason for hiding this comment

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

Approval for .enso changes

hubertp added 5 commits June 25, 2025 13:38
When reporting error diagnostics we need to analyze the error underlying
the `ExecutionException`, not the exception itself.
It now says 427, so adding +30 as a general rule.
Dunno on why would increase be needed.
Copy link
Member

@JaroslavTulach JaroslavTulach left a comment

Choose a reason for hiding this comment

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

  • I haven't tried to look at language server side of the change much
  • ExecutionService changes towards CompletionStage seem good
  • possibly they could be even more reactive to avoid on/off/on switching

}
return false;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: the previous version with two return statement in each if branch felt more functional to me.

return context.getThreadManager().submit(c);
}

private static <T> T resultOf(Future<T> future) {
Copy link
Member

Choose a reason for hiding this comment

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

Removal of resultOf blocking call marks ExecutionService as fully reactive (e.g. non-blocking) API. Good.

)
)

visualizationResultFuture.thenApply(visualizationResult => {
Copy link
Member

Choose a reason for hiding this comment

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

It's reactive!

public String getExceptionMessage(AbstractTruffleException panic) {
var future = submitExecution(() -> computeExceptionMessage(panic));
return resultOf(future);
public CompletionStage<String> getExceptionMessage(AbstractTruffleException panic) {
Copy link
Member

Choose a reason for hiding this comment

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

This one would very likely work better as:

CompletionStage<String> getExceptionMessage(CompletionStage<AbstractTruffleException> panic)

or something a like that being part of the reactive flow. It makes little sense to ex = toCompletableFuture().get() and then enter again the guest code thread by getExceptionMessage(ex).

The same comment applies to typeOfValue and other methods that inspect result of guest code execution.

@hubertp
Copy link
Collaborator Author

hubertp commented Jun 30, 2025

I will address the remaining comments in follow up PRs.

@hubertp hubertp merged commit c45de15 into develop Jun 30, 2025
78 of 79 checks passed
@hubertp hubertp deleted the wip/hubert/10525-prep-parallel-exec branch June 30, 2025 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: No changelog needed Do not require a changelog entry for this PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants