rules_kotlin icon indicating copy to clipboard operation
rules_kotlin copied to clipboard

Short class paths via ABI and JDeps

Open restingbull opened this issue 3 years ago • 0 comments

Background

  • ABI jars improve incremental compilation by lowering the number of affected libraries by only exposing the public areas.
  • Strict dependencies attempts to reduce the number of jars.
  • Compilation with pure strict dependencies violates the principal of least surprise -- Default compilation passes the transitive set of jars is passed to the compile action. This is necessary to ensure that the compiler is able to resolve all symbols. For example:

Given the following libraries:

flowchart
  LibB --> LibA
  LibC --> LibB

Classes:

classDiagram
  ClassA --|> ClassB
  ClassB --|> ClassC
  ClassA : String propertyA
  ClassC : String readPropertyA()

Compilation of LibC requires LibB and LibA. This requirement renders strict dependencies less effective as an optimization, as omitting the transitive dependency LibA creates a compilation error. This is contrary to the expectation of the developer.

Proposal

  • Hybrid approach of abi and strict dependencies
  • Use jdeps resolution to build an abi jar containing the direct deps and the referenced abi deps.
flowchart LR
  subgraph LibA
    ClassA
    ClassZ
    subgraph AbiA
         A
         Z
    end
  end

  subgraph LibB
     ClassB --> ClassA
     subgraph AbiB
         B --> CopyOfA
    end
  end

  subgraph LibC
     ClassC --> ClassB
  end

  LibC --> AbiB
  LibB --> AbiA

Benefits

  • Unlike including the transitive jars, produces a single jar with all references. This lowers the changes of unnecessary invalidation due to a transitive change
  • Reduces the size of the transitive class path
  • Maintains correctness

Drawbacks

  • Tree shake could be expensive.
  • Increases the size of the abi jar artifacts
  • Can increase the total bytes by including multiple copies of a given class

restingbull avatar Oct 24 '22 15:10 restingbull