Skip to content

Conversation

peterhall-unity3d
Copy link
Contributor

…setEditing around the loops which reimport all materials, significantly speeds up this process.


Purpose of this PR

When upgrading HDRP/URP version a material reimport is triggered. This operation refreshes the asset database for each material. On larger projects this can take ~10 seconds each time we refresh, and with 100s or 1000s of materials this leads to a reimport time of maybe a couple of hours. By placing calls to AssetDatabase.StartAssetEditing and AssetDatabase.StopAssetEditing around the import loop we can avoid doing the refresh operation, cutting the import time from (in a real world case) 3 hours to 3 minutes. In the HDRP sample project the import time is roughly cut in half from 12 seconds to 6 seconds.


Testing status

Manually tested upgrading HDRP version with and without this change in the HDRP test project and a large real world project.

…setEditing around the loops which reimport all materials, significantly speeds up this process.
@github-actions
Copy link

Hi! This comment will help you figure out which jobs to run before merging your PR. The suggestions are dynamic based on what files you have changed.
Link to Yamato: https://yamato.cds.internal.unity3d.com/jobs/902-Graphics
Search for your PR branch using the sidebar on the left, then add the following segment(s) to the end of the URL (you may need multiple tabs depending on how many packages you change)

HDRP
/.yamato%252Fall-hdrp.yml%2523PR_HDRP_trunk
With changes to HDRP packages, you should also run
/.yamato%252Fall-lightmapper.yml%2523PR_LightMapper_trunk

URP
/.yamato%252Fall-urp.yml%2523PR_URP_trunk
With changes to URP packages, you should also run
/.yamato%252Fall-lightmapper.yml%2523PR_LightMapper_trunk

Depending on the scope of your PR, you may need to run more jobs than what has been suggested. Please speak to your lead or a Graphics SDET (#devs-graphics-automation) if you are unsure.

@sebastienlagarde
Copy link
Contributor

Thanks for doing this PR. Could you add a changelog? (in hdrp and urp).
Also can you confirm that those call to asset database exist in previous version and that we can backport the PR (we will handle it for you)? thanks

@sebastienlagarde sebastienlagarde marked this pull request as ready for review September 24, 2021 16:51
@sebastienlagarde sebastienlagarde requested review from a team as code owners September 24, 2021 16:51
@sebastienlagarde
Copy link
Contributor

note yamato is green error come from master

@sebastienlagarde sebastienlagarde removed the request for review from slunity September 24, 2021 16:52
Copy link
Contributor

@RSlysz RSlysz left a comment

Choose a reason for hiding this comment

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

LGTM

@peterhall-unity3d
Copy link
Contributor Author

Thanks for doing this PR. Could you add a changelog? (in hdrp and urp).
Also can you confirm that those call to asset database exist in previous version and that we can backport the PR (we will handle it for you)? thanks

Yes, these calls exist back to 2018.4 (and beyond) so backporting should be fine:
https://docs.unity3d.com/2018.4/Documentation/ScriptReference/AssetDatabase.StartAssetEditing.html
https://docs.unity3d.com/2018.4/Documentation/ScriptReference/AssetDatabase.StopAssetEditing.html

Have added changelog entries and also wrapped the calls with a try/finally block as suggested by latest docs on those functions.

@sebastienlagarde
Copy link
Contributor

Waiting Felipe and urp qa approval.

@sebastienlagarde
Copy link
Contributor

For QA: merging to be sure this optimization is in the official release of 21.2

@sebastienlagarde sebastienlagarde merged commit 46fd1e9 into master Sep 30, 2021
@sebastienlagarde sebastienlagarde deleted the perf/optimize-reimport-all-materials branch September 30, 2021 13:21
@iM0ve
Copy link
Contributor

iM0ve commented Sep 30, 2021

I have tested by upgrading two projects - Amalienborg and HDRP Template. Did not encounter any related warnings/errors. All materials imported correctly

Images after upgrade
Unity_D3JZtE04rD

HwmeL6YLa5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants