Skip to content

Avoid name table pollution with fresh existentials#5506

Merged
adriaanm merged 1 commit intoscala:2.12.xfrom
retronym:topic/existential-ids
Nov 30, 2016
Merged

Avoid name table pollution with fresh existentials#5506
adriaanm merged 1 commit intoscala:2.12.xfrom
retronym:topic/existential-ids

Conversation

@retronym
Copy link
Member

@retronym retronym commented Nov 8, 2016

During large compilations runs, the large numbers of globally unique
fresh names for existentials captured from prefixes of asSeenFrom.
is a) somewhat wasteful (all these names are interned in the name table)
, and, b) form a pathological case for the current implementation of
Names#hashValue, which leads to overfull hash-buckets in the name table.

hashValue should probably be improved, but my attempts to do so have
shown a small performance degradation in some benchmarks. So this commit
starts by being more frugal with these names, only uniquely naming
within an asSeenFrom operation.

References scala/scala-dev#246

@scala-jenkins scala-jenkins added this to the 2.12.1 milestone Nov 8, 2016
During large compilations runs, the large numbers of globally unique
fresh names for existentials captured from prefixes of `asSeenFrom`.
is a) somewhat wasteful (all these names are interned in the name table)
, and, b) form a pathological case for the current implementation of
`Names#hashValue`, which leads to overfull hash-buckets in the name table.

`hashValue` should probably be improved, but my attempts to do so have
shown a small performance degradation in some benchmarks. So this commit
starts by being more frugal with these names, only uniquely naming
within an `asSeenFrom` operation.

References scala/scala-dev#246
@retronym retronym force-pushed the topic/existential-ids branch from b2c3a5d to 44dac96 Compare November 8, 2016 04:31
@retronym
Copy link
Member Author

retronym commented Nov 9, 2016

Review by @adriaanm

@lrytz
Copy link
Member

lrytz commented Nov 16, 2016

we could create a small class to encapsulate the variable

class FreshExistentialNameCreator {
  var counter
  def nm(suffix) = { counter += 1; newTypeName("_" + counter + suffix) }
}

def freshExistential(suffix: String, n: FreshExistentialNameCreator): TypeSymbol =
  newExistential(n.nm(suffix), pos)

// just err on the conservative side, i.e. with a bound that is too high.
// if(!(tparam.info.bounds contains tparam)) //@M can't deal with f-bounds, see #2251
capturedParamIds += 1
val capturedParamId = capturedParamIds
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the intent of the val? Is there some capture that this is avoiding? (I'm not seeing one.)

@adriaanm
Copy link
Contributor

I'm okay to merge as-is and come back and polish later.

@adriaanm
Copy link
Contributor

LGTM

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.

4 participants