Get dependencies faster than ComputeAllDependencies from UsdUtils

Hello, I’m a work study at Illogic Studios, Montpellier,

In order to get every dependencies of a USD stage in Houdini, I used ComputeAllDepencencies function in UsdUtils module.

But it seems that for external references it can take a lot of times, especially for references to heavy files like some bgeo.

I found this workaround below that modify the layer to remove references if there are not USD files, and store them and it is really faster.

DEPS = []

def filter_not_USD(assetPathProcessed):
    if not 'usd' in assetPathProcessed:
        global DEPS
        DEPS.append(os.path.normpath(assetPathProcessed))
        # Return an empty string to remove the asset path
        return ''
    return assetPathProcessed
    
def apply_filter(layer, dependencyInfo):
    layer.Reload(force=True)
    UsdUtils.ModifyAssetPaths(layer, filter_not_USD)
    
    return dependencyInfo
    
def getDependencies(asset_path: Sdf.AssetPath) -> list[str]:
    layer = Sdf.Layer.FindOrOpen(asset_path.path)
    if not layer:
        print(f"Failed to open layer: {asset_path.path}")
        return []
    layer.Reload(force=True)

    global DEPS
    DEPS = []

    UsdUtils.ModifyAssetPaths(layer, filter_not_USD)
    
    dependencies = UsdUtils.ComputeAllDependencies(layer.identifier, apply_filter)

I would like to know if there was a cleaner way to achieve the same result.

Hi @Patateon , can we first ask whether the bgeo “references” appear in a references, subLayers, payload arc or clipSets in an environment where referencing bgeo iles translates them to USD through a FileFormat plugin, or are they just appearing in asset valued attributes?

Hey @spiff, i just checked inside the USD file and my bgeo appears like this:

asset primvars:define_and_setup_ocean_procedural:spectra.timeSamples = {
    995: @../../../Scenefiles/FX/water/geo/FILM-010_water_v006.spectrav03_0995.bgeo.sc@,
    996: @../../../Scenefiles/FX/water/geo/FILM-010_water_v006.spectrav03_0996.bgeo.sc@,
    997: @../../../Scenefiles/FX/water/geo/FILM-010_water_v006.spectrav03_0997.bgeo.sc@,
    998: @../../../Scenefiles/FX/water/geo/FILM-010_water_v006.spectrav03_0998.bgeo.sc@,
    999: @../../../Scenefiles/FX/water/geo/FILM-010_water_v006.spectrav03_0999.bgeo.sc@,
    1000: @../../../Scenefiles/FX/water/geo/FILM-010_water_v006.spectrav03_1000.bgeo.sc@,
    1001: @../../../Scenefiles/FX/water/geo/FILM-010_water_v006.spectrav03_1001.bgeo.sc@,
    ...
}

So i suppose they are just appearing in asset valued attributes.

OK, that’s definitely perplexing, and we’d love to get to the bottom of it. If you can put your unfixed dependency computation in a standalone script, would you be able to run it with strace and send us the zipped output, so we can see what files are actually being opened?

That said, we do agree that we should provide an official way to do filtering of assets by name/pattern or extension, with the caveat that you may then miss some transitive dependencies, depending on what you filter.