zinc icon indicating copy to clipboard operation
zinc copied to clipboard

Could apiHash be computed as an unordered hash of the name hashes?

Open retronym opened this issue 5 years ago • 2 comments

val apiHash: HashAPI.Hash = HashAPI(classApi)
    val nameHashes = (new xsbt.api.NameHashing(options.useOptimizedSealed())).nameHashes(classApi)
    classApi.definitionType match {
      case d @ (DefinitionType.ClassDef | DefinitionType.Trait) =>
        val extraApiHash = {
          if (d != DefinitionType.Trait) apiHash
          else HashAPI(_.hashAPI(classApi), includePrivateDefsInTrait = true)
        }

        classApis(className) = ApiInfo(apiHash, extraApiHash, savedClassApi)
        classPublicNameHashes(className) = nameHashes.toArray
      case DefinitionType.Module | DefinitionType.PackageModule =>
        objectApis(className) = ApiInfo(apiHash, apiHash, savedClassApi)
        objectPublicNameHashes(className) = nameHashes.toArray

Now that name hashing is aways enabled, could we just redefine apiHash as f(nameHashes)? This would save about 10% of of the work in extract-api phase.

retronym avatar May 02 '20 23:05 retronym

Another implementation strategy would be to change hashDefinition to cache its result on the Definition that it hashes, so the subesquent call will avoid the work.

retronym avatar May 02 '20 23:05 retronym

image

retronym avatar May 02 '20 23:05 retronym