Skip to content
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

Speedup DataflowError.withDefaultTrace #11153

Merged
merged 12 commits into from
Oct 24, 2024

Conversation

Akirathan
Copy link
Member

@Akirathan Akirathan commented Sep 23, 2024

Fixes #10702

Pull Request Description

Improves the speed of ExecutionEnvironment.hasContextEnabled.

Important Notes

Local speedup of Map_Error_Benchmark_Vector_ignore.Map_Id_All_Errors benchmark is roughly ???.

Checklist

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

  • The documentation has been updated, if necessary.
  • Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.
  • 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.
  • Unit tests have been written where possible.

@Akirathan Akirathan added the CI: No changelog needed Do not require a changelog entry for this PR. label Sep 23, 2024
@Akirathan Akirathan self-assigned this Sep 23, 2024
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.

Consider @TruffleBoundary. If you want to keep BranchProfile approach, then it might be better to use the nodes approach - e.g. replace the withDefaultTrace method by class DataflowError.WithDefaultTraceNode and keep the profile hidden in it.

Anyway you are building on top of

and that code is clearly wrong. I like the speed up, but maybe we should fix the broken code first and only then measure the speed.

@JaroslavTulach JaroslavTulach self-requested a review September 23, 2024 12:24
@Akirathan
Copy link
Member Author

Waiting for @4e6.

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 am afraid right now this PR isn't ready to be merged. Moreover it needs to be adjusted to changes by Dmitry.

@Akirathan Akirathan force-pushed the wip/akirathan/10702-dataflowerr-stack-regression branch from baeddd0 to 5c1e9d1 Compare October 14, 2024 13:56
@Akirathan
Copy link
Member Author

#11153 (comment) : This line fixes the problem? That is surprising

You are right. My initial commit is clearly wrong. I will revert it, rebase on latest develop, and start over.

Copy link
Contributor

mergify bot commented Oct 14, 2024

⚠️ The sha of the head commit of this PR conflicts with #11321. Mergify cannot evaluate rules on this PR. ⚠️

2 similar comments
Copy link
Contributor

mergify bot commented Oct 14, 2024

⚠️ The sha of the head commit of this PR conflicts with #11321. Mergify cannot evaluate rules on this PR. ⚠️

Copy link
Contributor

mergify bot commented Oct 14, 2024

⚠️ The sha of the head commit of this PR conflicts with #11321. Mergify cannot evaluate rules on this PR. ⚠️

var dataflowStacktraceCtx = ensoCtx.getBuiltins().context().getDataflowStackTrace();
// dataflowStacktraceCtx is a compiler constant, because it is a constructor of a builtin
// type.
CompilerAsserts.partialEvaluationConstant(dataflowStacktraceCtx);
Copy link
Member Author

Choose a reason for hiding this comment

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

This helps with the performance. The compiler is most probably not able to determine that dataflowStacktraceCtx is actually a constant (reference to a constructor of a builtin type).

Copy link
Member

Choose a reason for hiding this comment

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

This helps with the performance.

That would be surprising. It is a CompilerAsserts - e.g. not a directive, but only an assert that something is true. E.g. either dataflowStacktraceCtx is constant or the compilation is going to fail. The fact whether it is constant or not isn't changed by the assert. The fact whether compilation goes or not is influenced by the assert.

@Akirathan
Copy link
Member Author

Akirathan commented Oct 16, 2024

With the changes in 243847c I managed to get the performance of Map_Error_Benchmark_Vector_ignore.Map_Id_All_Errors from 1.179 ± 0.648 to 0.981 ± 0.073 (note that the standard deviation is also much lower, which is a good thing as it suggests the score is more reliable). Since the execution environment itself cannot be treated as a constant, I'd say this is a reasonable gain for such a small modification.

@Akirathan Akirathan force-pushed the wip/akirathan/10702-dataflowerr-stack-regression branch from f113ce7 to 243847c Compare October 16, 2024 11:35
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.

The use of Permissions seems to go the right way.

var dataflowStacktraceCtx = ensoCtx.getBuiltins().context().getDataflowStackTrace();
// dataflowStacktraceCtx is a compiler constant, because it is a constructor of a builtin
// type.
CompilerAsserts.partialEvaluationConstant(dataflowStacktraceCtx);
Copy link
Member

Choose a reason for hiding this comment

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

This helps with the performance.

That would be surprising. It is a CompilerAsserts - e.g. not a directive, but only an assert that something is true. E.g. either dataflowStacktraceCtx is constant or the compilation is going to fail. The fact whether it is constant or not isn't changed by the assert. The fact whether compilation goes or not is influenced by the assert.

@JaroslavTulach JaroslavTulach dismissed their stale review October 16, 2024 12:40

The use of Permissions seems to go the right way!

boolean doIt(
ExecutionEnvironment executionEnvironment,
AtomConstructor runtimeCtxCtor,
@Cached("executionEnvironment") ExecutionEnvironment cachedEnv) {
Copy link
Member Author

Choose a reason for hiding this comment

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

With cached ExecutionEnvironment, the performance improved from 1.179 ± 0.648 to 0.218 ± 0.014.

@Akirathan Akirathan added the CI: Clean build required CI runners will be cleaned before and after this PR is built. label Oct 18, 2024
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.

The idea of replacing array with record with three fields looks fine. If there is speed up, then we can probably integrate.

@Akirathan Akirathan added the CI: Ready to merge This PR is eligible for automatic merge label Oct 22, 2024
@mergify mergify bot merged commit c839309 into develop Oct 24, 2024
40 of 41 checks passed
@mergify mergify bot deleted the wip/akirathan/10702-dataflowerr-stack-regression branch October 24, 2024 03:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: Clean build required CI runners will be cleaned before and after this PR is built. CI: No changelog needed Do not require a changelog entry for this PR. CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

stdlib benchmarks regression: DataflowError with stack
2 participants