How do assemblies actually work?

From what I understand assemblies reduce compile times by only modifying the related assemblies. However, I would like some clarification on which side gets compiled.

Example: If I have an assembly that uses TextMeshPro, when I edit the script in the assembly will that also recompile textmeshpros library? Or does it compile for both sides only if I were to edit something in TextMeshPro’s assembly?

When code is updated, recompiling dependent assemblies (code used by it) is a thing, and recompiling dependency assemblies (code it uses) is not a thing. That would be entirely pointless.

Think about it this way. You have code that needs to use Unity Mathematics. Why would changing your code require recompiling Unity Mathematics? Nothing about it is different when you rewrite your code, so there’s no reason for Unity Mathematics to be recompiled. On the other hand, if Unity Mathematics gets some update to fix some edge case or add a few methods, assemblies that use Unity Mathematics should be recompiled to make sure the assembly is up to date with and correctly bound to the code in Unity Mathematics. In turn, once assemblies directly referencing it have recompiled, any assemblies that use those assemblies should themselves be recompiled, at least if that assembly ended up changing when recompiled.

Basically, you can reason about this in terms of what requires an update in a directed acyclic graph of compilation inputs and the resulting artifacts. Any changes to asmdef/asmref files, C# source files, compiler response files, defined symbols, analyzers / source generators, source generator additional files, dependency assemblies, etc. can invalidate the assembly and trigger recompilation. The resulting assembly being different would then be considered a modified input for the assemblies that depend on it, so those would be recompiled as well, and so on until everything in the graph is up to date. If all the inputs are the same, nothing has to recompile.

7 Likes

Thanks for the clarification.