Skip to content

Add hybrid-duplication-audit skill - #129

Open
timt-unity3d wants to merge 2 commits into
mainfrom
skills/hybrid-duplication-audit
Open

Add hybrid-duplication-audit skill#129
timt-unity3d wants to merge 2 commits into
mainfrom
skills/hybrid-duplication-audit

Conversation

@timt-unity3d

Copy link
Copy Markdown
Collaborator

Summary

  • Adds Skills/hybrid-duplication-audit, a Claude Code skill that audits asset duplication across the AssetBundle / ContentDirectory boundary in a hybrid Addressables 4.x build (some groups build to .bundle files, others build through BuildPipeline.BuildContentDirectory).
  • The skill runs one analyze invocation combining the Addressables build layout report with the content directory build output, then matches source-asset paths across addressables_build_explicit_assets / addressables_build_data_from_other_assets and content_layout_source_assets to find what's genuinely duplicated.
  • Matching by asset path (rather than object CRC) catches cases a plain CRC diff misses — for example the same shader built with a different variant set on each side, which is also why Addressables' own DuplicatedAssetCount can read 0 even when real cross-boundary duplication exists.
  • Adds short cross-links in README.md, AGENTS.md, and Documentation/analyzer.md for discoverability, following this repo's existing manual-index convention.

Test plan

  • Built UnityDataTool from this branch and ran Skills/hybrid-duplication-audit/scripts/Compare-HybridDuplication.ps1 against a real hybrid Addressables project, confirming it reproduces a hand-verified duplication total (three shared shaders, 214,824 bytes) exactly.
  • Ran the script against a content-directory-only (non-hybrid) build and confirmed it reports "this is not a hybrid build" cleanly rather than a misleading result.
  • Verified -KeepDatabase preserves the generated database and its tables are as documented.
  • Reviewer sanity-check: run the script against your own hybrid Addressables project.

Audits asset duplication across the AssetBundle / ContentDirectory
boundary in a hybrid Addressables 4.x build. Runs one `analyze`
combining the Addressables build layout report with the content
directory build output, then matches source-asset paths across both
- catching cases a CRC-based diff misses, such as a shader built with
a different variant set on each side (which is also why Addressables'
own DuplicatedAssetCount can read 0 even when real duplication
exists).
Linux/macOS equivalent of Compare-HybridDuplication.ps1 - same
defaults, same queries, same output. Verified against this session's
build data: reproduces the PowerShell version's result exactly.

@SkowronskiAndrew SkowronskiAndrew left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I remembered i hadn't looked at this yet. I am giving some quick feedback but ran out of time to read the skill fully. This does seem very helpful because it is tricky to figure out how to use UnityDataTools for a hybrid build, and raises some interesting questions about what comparison means for Shaders and when and how we should analyze the actual content as well.

name: hybrid-duplication-audit
description: Audits asset duplication across the AssetBundle / ContentDirectory boundary in a hybrid Addressables 4.x build, where some groups build to .bundle files and others build through BuildPipeline.BuildContentDirectory. Use when asked to compare duplication in a hybrid project, find what's duplicated between bundles and the content directory, explain why Addressables' own DuplicatedAssetCount reads 0 or looks too low despite shared shaders, textures, or meshes across bundle and content-directory groups, or size the "hybrid tax" of assets baked twice because an AssetBundle cannot reference content-directory content. Runs one UnityDataTool analyze combining the Addressables build layout report with the content directory build output, then matches source-asset paths across both to find what's genuinely duplicated — including cases a plain CRC/hash diff misses, such as the same shader built with a different variant set on each side.
compatibility: Requires UnityDataTool (github.com/Unity-Technologies/UnityDataTools) built from a version with ContentLayout.json support, sqlite3 on PATH, and a completed hybrid Addressables 4.x build (at least one AssetBundle-producing group and one ContentDirectoryGroupSchema group).
---

@SkowronskiAndrew SkowronskiAndrew Aug 22, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this description could be slimmed down, it feels like it gets far into details, and all that would get loaded in the context even if doing completely different work with UnityDataTools?

(Eventually I think we should have a "analyze" skill, or "compare-builds" skill that acts as a guide for other specific skills to use depending on the type of build but thats not needed immediately for this PR)

Write-Output " Build history: $BuildHistory"
Write-Output ""

& $resolvedToolPath analyze $BuildLayout $ContentDirectory --build-history $BuildHistory -o $Database

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One detail, although I'm not certain how to "fix it" with the existing analyze API. It seems you do full analysis of the all the content directory serialized files (because it is an argument) but you don't ever use that information in the queries (because the content_layout file is what we need). Meanwhile we don't analyze the asset bundles.

I think this is happening because in order to find the correct build history entry we want the BuildManifestHash.txt file. But the act of providing that info is resulting in a full scan.

We may face similar situation for Addressables when we move the layout file into build history. E.g. we want to match the output to the correct build history entries. But for this calculation we don't strictly need to do the big analysis of the contents.

On the other hand maybe doing the full analysis will be worth it - i think that differing CRCs is important information because two shaders that have different variants are not really a duplicate of the same built content (but its important information that they are the same shader)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I was thinking perhaps we should have a separate script for finding the buildhistory folder from the build output folder. Maybe even part of a "buildhistory" command in UnityDataTools instead of being a script inside the skill.

So the helper would take care of the detail of finding the correct folder with the ContentLayout.json file based on the manifest hash, and then when calling analyze we pass in the specific ContentLayout.json file as an argument. That avoids doing a full analysis of all the ContentDirectory content just for getting a single hash value.

(We can also think how that we should look into finding the Addressables layout file in a general way that works with both the current Library structure and the upcoming BuildHistory integration, but that could be deferred)

On the other hand, its possible that always analyzing the build content is better, e.g. to get CRC values and supporting certain comparison operations, so my line of thinking about the optimization may be going the wrong direction. I just know that a full analysis with all references can take 30 minutes and produce a database that is hundred of MB large so thats not good for a temporary database if we never look at the resulting tables.

Comment thread Documentation/analyzer.md
forms doesn't necessarily produce byte-identical objects (a shader's variants, for example, are
stripped independently on each side), so CRC matching can miss it entirely. See
[Skills/hybrid-duplication-audit](../Skills/hybrid-duplication-audit/SKILL.md) for a query that
matches by source asset path instead, which catches this case.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this paragraph needs a bit more context to explain what scenario it is talking about, it starts talking, e.g. that it is clear that it is about hybrid Addressables builds. I'm not actually sure how assetbundle specific this view is currently, the docs so far talk only about AssetBundles.

I also think that different variants between shaders is an important detail, that is not a duplicate in the sense of it being completely identical

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.

2 participants