Skip to content

Fix #11885: Always clone trees if position already set #11960

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 1 commit into from
May 25, 2021

Conversation

liufengyun
Copy link
Contributor

@liufengyun liufengyun commented Mar 31, 2021

Fix #11885: Always clone trees if position already set

The cause of the problem is that we use parallelism in Pickler:

  if !Pickler.ParallelPickling || ctx.settings.YtestPickler.value then force()

Sometimes on Windows, the futures run a little slower, and the later
phase Inlining can change the positions of the trees to be pickled,
thus non-determinism.

For the Dotty project, the statistics is as follows:

  • Before: ntrees = 5331539
  • After: ntrees = 5334075

Performance-wise, this should be better than synchronizing the pickling tasks.

[test_windows_full]

@liufengyun liufengyun changed the title Fix #11885: Avoid non-determinism of idempotency testts on Windows Fix #11885: Avoid non-determinism of idempotency tests on Windows Mar 31, 2021
@liufengyun liufengyun force-pushed the fix-11885b branch 2 times, most recently from f26c27b to 8e1fb65 Compare March 31, 2021 15:05
Copy link
Member

@smarter smarter left a comment

Choose a reason for hiding this comment

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

We should fix the non-determinism problem rather than working around it in the tests because we really want the compiler output to be idempotent to make builds reproducible: scala/scala-dev#405

@liufengyun liufengyun force-pushed the fix-11885b branch 3 times, most recently from 7397e6f to 0bda3f9 Compare March 31, 2021 17:08
Comment on lines 91 to 94
* On Windows we observe non-deterministic failure for the
* idempotency test tests/pos/i6507b.scala. The cause of the
* non-determinism is that the positions of the to be pickled
* trees might change in a later phase `Inlining` after pickling.
Copy link
Member

Choose a reason for hiding this comment

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

@nicolasstucki Could Inlining avoid changing tree positions? Otherwise we could copy the tree first, this should still be more efficient than forcing pickling early.

Copy link
Contributor

Choose a reason for hiding this comment

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

Inlining is not supposed to change positions, Inlined nodes are supposed to have the same position as the original tree. Could be a bug setting the positions or maybe it is constant folding that removes some positions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Even if we fix the bug in inlining, it's so easy to re-introduce the bug in the future.

Or, we add an assertion in def span_= to check that spans are only set once. It seems to be a reasonable invariant.

@liufengyun
Copy link
Contributor Author

liufengyun commented Mar 31, 2021

test performance please

@dottybot
Copy link
Member

performance test scheduled: 1 job(s) in queue, 0 running.

@dottybot
Copy link
Member

Performance test finished successfully:

Visit https://dotty-bench.epfl.ch/11960/ to see the changes.

Benchmarks is based on merging with master (4ab402c)

@dottybot
Copy link
Member

dottybot commented Apr 1, 2021

performance test scheduled: 1 job(s) in queue, 1 running.

@dottybot
Copy link
Member

dottybot commented Apr 1, 2021

Performance test finished successfully:

Visit https://dotty-bench.epfl.ch/11960/ to see the changes.

Benchmarks is based on merging with master (86b4d62)

@liufengyun liufengyun changed the title Fix #11885: Avoid non-determinism of idempotency tests on Windows Fix #11885: Always clone trees if position already set Apr 19, 2021
@liufengyun
Copy link
Contributor Author

As an update, I've changed the fix to always clone if the position is not empty.

For the Dotty project, the statistics is as follows:

  • Before: ntrees = 5331539
  • After: ntrees = 5334075

Performance-wise, this should be better than synchronizing the pickling tasks.

@liufengyun liufengyun requested a review from smarter April 27, 2021 08:02
@smarter
Copy link
Member

smarter commented Apr 27, 2021

Since we're currently tracking a performance regression (#12153 (comment), #12229), I'd like to wait until we've fixed it before investigating the potential performance impact of this PR

@smarter
Copy link
Member

smarter commented May 14, 2021

test performance please

@dottybot
Copy link
Member

Performance test finished successfully:

Visit https://dotty-bench.epfl.ch/11960/ to see the changes.

Benchmarks is based on merging with master (b559209)

Copy link
Member

@smarter smarter left a comment

Choose a reason for hiding this comment

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

The filtering of i6507b.scala in IdempotencyTests.scala should be removed too, otherwise LGTM.

Comment on lines 68 to 75
if (mySpan.isSynthetic) {
if (!mySpan.exists && span.exists)
envelope(source, span.startPos) // fill in children spans
this
this
else
cloneIn(source)
}
else cloneIn(source)
Copy link
Member

Choose a reason for hiding this comment

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

I think this can be simplified to:

        if !mySpan.exists then
          if span.exists then envelope(source, span.startPos) // fill in children spans
          this
        else
          cloneIn(source)

The cause of the problem is that we use parallelism in Pickler:

      if !Pickler.ParallelPickling || ctx.settings.YtestPickler.value then force()

Sometimes on Windows, the futures run a little slower, and the later
phase `Inlining` can change the positions of the trees to be pickled,
thus non-determinism.

For the Dotty project, the statistics is as follows:

- Before: ntrees = 5331539
- After:  ntrees = 5334075

Performance-wise, this should be better than synchronizing the pickling tasks.
@scala scala deleted a comment from dottybot May 25, 2021
@liufengyun
Copy link
Contributor Author

retest performance please

@dottybot
Copy link
Member

performance test scheduled: 1 job(s) in queue, 0 running.

@dottybot
Copy link
Member

Performance test finished successfully:

Visit https://dotty-bench.epfl.ch/11960-1/ to see the changes.

Benchmarks is based on merging with master (af0de81)

@liufengyun liufengyun merged commit 2bfa8e2 into scala:master May 25, 2021
@liufengyun liufengyun deleted the fix-11885b branch May 25, 2021 12:45
@Kordyjan Kordyjan added this to the 3.0.1 milestone Aug 2, 2023
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.

IdempotencyTests is flaky on Windows
5 participants