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

Optimize and simplify SourcePosition handling #9561

Merged
merged 2 commits into from Aug 14, 2020

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Aug 14, 2020

SourcePosition shows up high in the allocation charts: ~130'000 for
typer/.scala, i.e. 10 per line. We already have cut down on
SourcePosition allocations by passing Positioned instead of SourcePosition
where it makes sense. This PR generalizes this aproach: A new type
SrcPos creates a SourcePosition on demand. it is implemented
by SourcePosition itself, as well as Positioned and Symbol.
Where possible we use SrcPos instead of SourcePosition, thereby
delaying the creation of source positions. For typer/
.scala, this
cut down allocations from 130K to 9K.

@odersky
Copy link
Contributor Author

odersky commented Aug 14, 2020

I propose to get this in quickly. It's a significant simplification to what we had before.

Before, report methods took SourcePositions which are expensive to create. So we did various tricks to avoid creating them, for instance by using Positioned types that carried the source position and that were passed around instead. Nevertheless, we still create about 10 source positions per source line, which makes source position one of the most often allocated types.

Now, we have a new type SrcPos that is extended by SourcePosition, Positioned, and Symbol. SrcPos is a type that provides a SourcePosition on request. report methods take SrcPos arguments.

Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

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

LGTM

One conceptual question: can we reuse Positioned to play the role of SrcPos?

compiler/src/dotty/tools/dotc/util/Stats.scala Outdated Show resolved Hide resolved
@liufengyun
Copy link
Contributor

test performance please

@dottybot
Copy link
Member

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

@dottybot
Copy link
Member

performance test failed:

Please check http://lamppc37.epfl.ch:8000/pull-9561-08-14-14.54.out for more information

odersky and others added 2 commits August 14, 2020 16:52
SourcePosition shows up high in the allocation charts: ~130'000 for
typer/*.scala, i.e. 10 per line. We already have cut down on
SourcePosition allocations by passing Positioned instead of SourcePosition
where it makes sense. This PR generalizes this aproach: A new type
`SrcPos` creates a `SourcePosition` on demand. it is implemented
by `SourcePosition` itself, as well as `Positioned` and `Symbol`.
Where possible we use `SrcPos` instead of `SourcePosition`, thereby
delaying the creation of source positions. For typer/*.scala, this
cut down allocations from 130K to 9K.
Co-authored-by: Fengyun Liu <liu@fengy.me>
@odersky
Copy link
Contributor Author

odersky commented Aug 14, 2020

test performance please

@dottybot
Copy link
Member

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

@odersky
Copy link
Contributor Author

odersky commented Aug 14, 2020

@liufengyun Positioned is a supertype of Tree and untpd.Mod, so it is more specific than SrcPos.

@odersky odersky merged commit 4beb03a into scala:master Aug 14, 2020
@odersky odersky deleted the simplify-positions branch August 14, 2020 16:02
@dottybot
Copy link
Member

Performance test finished successfully:

Visit http://dotty-bench.epfl.ch/9561/ to see the changes.

Benchmarks is based on merging with master (17c5dc1)

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.

None yet

3 participants