Compiling Scripts Suddenly Takes Extremely Long

Version: 2021.3.8

I noticed a few weeks ago that script compiling was taking exorbitantly long, so I uninstalled and reinstalled the editor, and the problem remains. In the freshly installed editor, opening a completely blank 3D template project prompts a script compilation of about 7 minutes. When creating new scripts or making minor modifications to existing ones, compile times are a few seconds about 1/3 of the time and 2-4 minutes the rest of the time, which is a real hinderance. Any thoughts?

Not sure if it is related, but opening a fresh project also consistently brings up this very long package error (the error only appears once when the new project is made and then never again):

The package cache was invalidated and rebuilt because the following immutable asset(s) were unexpectedly altered:
Packages/com.unity.timeline/Runtime/Scripting/PlayableTrack.cs
Packages/com.unity.purchasing/Runtime/Stores/Android/GooglePlay/AAR/Models
Packages/com.unity.timeline/Editor/Window/ViewModel/TimelineWindowViewPrefs.cs
Packages/com.unity.ads/Editor/Source/SkAdNetworkRemoteSource.cs
Packages/com.unity.textmeshpro/Scripts/Editor/TMP_UIStyleManager.cs
Packages/com.unity.timeline/Editor/StyleSheets/Images/Icons/TrackLockButtonEnabled@2x.png
Packages/com.unity.ugui/Runtime/UI/Core
Packages/com.unity.timeline/Editor/Actions/TimelineActions.cs
Packages/com.unity.timeline/Editor/StyleSheets/Images/Icons/TrackAvatarButtonDisabled@2x.png
Packages/com.unity.collab-proxy/Editor/Collaborate/Views
Packages/com.unity.purchasing/Editor/ServiceProjectSettings/UI
Packages/com.unity.collab-proxy/Editor/Collaborate/Assets/Icons/clear-dark@2x.png
Packages/com.unity.ugui/Editor/UI/GraphicEditor.cs
Packages/com.unity.settings-manager/Tests/Editor
Packages/com.unity.ads/Editor/Parser/SkAdNetworkJsonParser.cs
Packages/com.unity.timeline/Editor/Window/TimelineWindow_PreviewPlayMode.cs
Packages/com.unity.timeline/Editor/StyleSheets/Images/Icons/TrackMarkerButtonDisabled@2x.png
Packages/com.unity.collab-proxy/Editor/PlasticSCM/Views/IncomingChanges/Gluon/IncomingChangesTreeHeaderState.cs
Packages/com.unity.purchasing/Plugins/UnityPurchasing/unitypurchasing.bundle/Contents/Resources/en.lproj/InfoPlist.strings
Packages/com.unity.timeline/Runtime/Events/SignalTrack.cs
Packages/com.unity.purchasing/Editor/Analytics/Helpers/GenericEditorFieldEditEventSenderHelpers.cs
Packages/com.unity.purchasing/Editor/WebRequest/Interface
Packages/com.unity.timeline/Editor/Window/TimelineWindowAnalytics.cs
Packages/com.unity.collab-proxy/Editor/Collaborate/Components/Menus/FloatingDialogue.cs
Packages/com.unity.settings-manager/Tests/Editor/SettingsTests.cs
Packages/com.unity.package-validation-suite/Editor/ValidationSuite/ValidationTests/LifecycleValidation.cs
Packages/com.unity.ads/Plugins/iOS/UnityAds.framework/Headers/UPURTransactionError.h
Packages/com.unity.ugui/Tests/Editor/UnityEvent
Packages/com.unity.timeline/Editor/Window/Modes/TimelineInactiveMode.cs
Packages/com.unity.purchasing/Editor/AppStoreExtensionMethods.cs
Packages/com.unity.timeline/Runtime/Evaluation/RuntimeElement.cs
Packages/com.unity.collab-proxy/Editor/PlasticSCM/Assets/Images/d_expertbuhoshe.png
Packages/com.unity.modules.uielements
Packages/com.unity.ugui/Tests/Editor/EventSystem
Packages/com.unity.purchasing/Runtime/Purchasing/UnifiedReceipt.cs
Packages/com.unity.analytics/Tests/Editor/AdSkipTests.cs
Packages/com.unity.timeline/Editor/StyleSheets/Images/Icons/TrackLockButtonDisabled@2x.png
Packages/com.unity.ads/Runtime/Advertisement/Events/StartEventArgs.cs
Packages/com.unity.purchasing/Runtime/Stores/Android/GooglePlay/Services/GooglePlayStoreRetrieveProductsService.cs
Packages/com.unity.timeline/Editor/StyleSheets/Images/LightSkin/TimelineSignalCollapsed.png
Packages/com.unity.test-framework/UnityEditor.TestRunner/GUI/TestListTreeView/TestTreeViewItem.cs
Packages/com.unity.ads/Editor/DevX/Settings/UiConstants.cs
Packages/com.unity.collab-proxy/Lib/Editor/PlasticSCM/localization/basecommands.en.txt
Packages/com.unity.ads/Tests
Packages/com.unity.purchasing/Runtime/Stores/BaseStore
Packages/com.unity.2d.tilemap/Editor/EditorTools/BrushToolsAttribute.cs
Packages/com.unity.ads/Tests/Editor/Monetization/PromoMetadataTests.cs
Packages/com.unity.timeline/DocCodeExamples/TimelineEditorExamples.cs
Packages/com.unity.test-framework/UnityEngine.TestRunner/Assertions/UnityTestTimeoutException.cs
Packages/com.unity.collab-proxy/Editor/PlasticSCM/Assets/Styles/PlasticWindow
Packages/com.unity.timeline/Editor/Window/TimelineWindow_PlayableLookup.cs
Packages/com.unity.timeline/Runtime/Utilities/AnimatorBindingCache.cs
Packages/com.unity.textmeshpro/Scripts/Editor/TMP_SpriteAssetImporter.cs
Packages/com.unity.collab-proxy/Editor/Collaborate/Assets/Layouts/ChangesTabPageView.uxml
Packages/com.unity.package-validation-suite/Lib/Editor/Unity.APIComparison.Framework.dll
Packages/com.unity.2d.tilemap/Editor/GridPaintTargetsDropdown.cs
Packages/com.unity.test-framework/UnityEngine.TestRunner/Utils/AssemblyProvider/PlayerTestAssemblyProvider.cs
Packages/com.unity.collab-proxy/Editor/Collaborate/Assets/Icons/loading-dark.png
Packages/com.unity.ads/Tests/Editor/Advertisement
Packages/com.unity.collab-proxy/Editor/Collaborate/Unity.CollabProxy.Editor.asmdef
Packages/com.unity.collab-proxy/Editor/Collaborate/Assets/Icons/more-vert-light@2x.png
Packages/com.unity.collab-proxy/Editor/PlasticSCM/Views/PendingChanges/Dialogs/FilterRulesConfirmationDialog.cs
Packages/com.unity.collab-proxy/Lib/Editor/PlasticSCM/localization/clientcommon.en.txt
Packages/com.unity.2d.tilemap/Editor/GridPaletteAddPopup.cs
Packages/com.unity.textmeshpro/Tests/Editor/Unity.TextMeshPro.Editor.Tests.asmdef
Packages/com.unity.collab-proxy/Editor/Collaborate/Components/ChangeListElements/BaseChangeListElement.cs
Packages/com.unity.timeline/Editor/Signals/SignalReceiverInspector.cs
Packages/com.unity.purchasing/Runtime/AppleMacos/OSXStoreBindings.cs
Packages/com.unity.timeline/Editor/Actions/ClipsActions.cs
Packages/com.unity.services.core/Editor/Core/ServiceActivationPopup
Packages/com.unity.test-framework/UnityEditor.TestRunner/CommandLineParser/CommandLineOptionSet.cs
Packages/com.unity.textmeshpro/Scripts/Editor/TMPro_CreateObjectMenu.cs
Packages/com.unity.purchasing/Runtime/Purchasing/PurchasingManager.cs
Packages/com.unity.timeline/Runtime/AssetUpgrade
Packages/com.unity.ugui/Tests/Runtime/TextEditor/TextEditorBackspaceDelete.cs
Packages/com.unity.2d.sprite/Editor/ObjectMenuCreation/DefaultAssets/Textures
Packages/com.unity.collab-proxy/Editor/PlasticSCM/Assets/Images/iconmoved.png
Packages/com.unity.timeline/Runtime/Activation/ActivationTrack.cs
Packages/com.unity.collab-proxy/Editor/PlasticSCM/Assets/Images/iconcheckedoutlocaloverlay.png
Packages/com.unity.timeline/Editor/inspectors/EditorClip.cs
Packages/com.unity.xr.legacyinputhelpers/README.md
Packages/com.unity.timeline/Editor/treeview/Manipulator.cs
Packages/com.unity.ugui/Runtime/EventSystem/InputModules/BaseInput.cs
Packages/com.unity.test-framework/UnityEngine.TestRunner/NUnitExtensions/Runner/RestoreTestContextAfterDomainReload.cs
Packages/com.unity.test-framework/UnityEditor.TestRunner/TestResultSerializer.cs
Packages/com.unity.collab-proxy/Editor/Collaborate/Components/AdapterListView.cs
Packages/com.unity.ads/Plugins/iOS/UnityAds.framework/Headers/UnityAdsError.h
Packages/com.unity.collab-proxy/Editor/PlasticSCM/Configuration/MissingEncryptionPasswordPromptHandler.cs
Packages/com.unity.collab-proxy/Editor/Collaborate/Assets/Icons/status-error-light@2x.png
Packages/com.unity.test-framework/UnityEditor.TestRunner/Api/CallbacksDelegator.cs
Packages/com.unity.purchasing/Runtime/Purchasing/Utilites/ProductPurchaseUpdater.cs
Packages/com.unity.collab-proxy/Editor/PlasticSCM/Views/CreateWorkspace
Packages/com.unity.ugui/Tests/Runtime/Canvas/SiblingOrderChangesLayout.cs
Packages/com.unity.purchasing/Icons/LinkBlack.png
Packages/com.unity.ide.visualstudio/Editor/KnownAssemblies.cs
Packages/com.unity.timeline/Editor/treeview/IPropertyKeyDataSource.cs
Packages/com.unity.purchasing/Runtime/WinRT/ICurrentApp.cs
Packages/com.unity.timeline/Editor/Window/Modes/TimelineMode.cs
Packages/com.unity.collab-proxy/Editor/PlasticSCM/Tool/IsExeAvailable.cs
Packages/com.unity.collab-proxy/Editor/PlasticSCM/Configuration/CloudEdition
Packages/com.unity.purchasing/Runtime/Stores/Android/GooglePlay/AAR/GooglePurchaseService.cs
Packages/com.unity.services.core/Editor/Core/AsyncOperation/AsyncOperationAwaiter.cs
Packages/com.unity.purchasing/Runtime/Security/Asn1Processor/Asn1Util.cs
Packages/com.unity.collab-proxy/Editor/PlasticSCM/AssetsUtils/Processor
Packages/com.unity.ugui/Tests/Editor/Slider/SliderRectReferences.cs
Packages/com.unity.ads/Plugins/iOS/UnityAdsPurchasingWrapper.h
Packages/com.unity.modules.androidjni/package.ModuleCompilationTrigger
Packages/com.unity.ext.nunit/net35/unity-custom
Packages/com.unity.collab-proxy/Editor/PlasticSCM/CheckWorkspaceTreeNodeStatus.cs
Packages/com.unity.timeline/Editor/StyleSheets/Images/Shared/TimelineBottomShadow.png
Packages/com.unity.test-framework/UnityEditor.TestRunner/Api/RunState.cs
Packages/com.unity.collab-proxy/Editor/PlasticSCM/Configuration/CloudEdition/Welcome/OrganizationPanel.cs
Packages/com.unity.purchasing/Runtime/Stores/Android/GooglePlay/AAR/Interfaces/IBillingClientStateListener.cs
Packages/com.unity.collab-proxy/Editor/PlasticSCM/Assets/Styles/PlasticWindow/PlasticWindow.dark.uss
Packages/com.unity.timeline/Editor/Window/TimelineWindow_Manipulators.cs
Packages/com.unity.purchasing/Editor/ServiceProjectSettings/UI/StyleSheets/ServicesProjectSettingsLight.uss
Packages/com.unity.analytics/Tests/Editor/CutsceneStartTests.cs
Packages/com.unity.ads/Plugins/iOS/UnityAds.framework/UnityAds
Packages/com.unity.test-framework/UnityEngine.TestRunner/TestRunner/SynchronousFilter.cs
Packages/com.unity.purchasing/Editor/GooglePlayProductCatalogExporter.cs
Packages/com.unity.ugui/Tests/Runtime/LayoutGroup
Packages/com.unity.timeline/Editor/Utilities/CustomTrackDrawerAttribute.cs
Packages/com.unity.collab-proxy/Editor/PlasticSCM/UI/EditorProgressControls.cs
Packages/com.unity.timeline/Editor/StyleSheets/Images/Icons/TrackCurvesButtonEnabled.png
Packages/com.unity.ide.rider/Rider/Editor/UnitTesting
Packages/com.unity.purchasing/Runtime/Purchasing/AnalyticsReporter.cs
Packages/com.unity.textmeshpro/PackageConversionData.json
Packages/com.unity.nuget.mono-cecil/Tests
Packages/com.unity.analytics/Tests/Editor/AdStartTests.cs
Packages/com.unity.collab-proxy/Editor/PlasticSCM/Views/PendingChanges/Dialogs/EmptyCheckinMessageDialog.cs
Packages/com.unity.collab-proxy/Editor/PlasticSCM/Views/Diff/ClientDiffTreeViewItem.c

I’m inclined to say that this sounds more likely to be an issue with your system, since this still happens after reinstalling and in a newly created project.

Pull out the Profiler, set it to edit mode and enable deep profiling. Then provoke one of those long recompile times. Perhaps this points to something but I doubt it.

You should also check if and what gets logged to editor.log between start and finish of a long compilation cycle.

As to system, there can be many causes. Virus scanner, running out of memory (disk swapping), SSD nearly full (often causes slowdowns), failing HDD (slowdowns due to re-reads and sector re-alloc), background tasks (defrag, scan, search, indexing), malware …

The long list of unexpectedly altered package cache could indicate disk failures or running out of disk space. Run a disk diagnosis and the disk cleanup tool.

Have you seen similar behavior with any other applications?

Thanks for the pointers! I don’t think it’s a disk issue because I have plenty of open space and disk diagnosis doesn’t reveal any issues. I’m unfamiliar with the profiler and can’t seem to get it to work while compiling - it freezes up during compilation and restarts collecting data when it’s done, so I’m not sure about what I can get out of that. However, I did check the editor log and found several suspicious looking lines from during compilation:

*** Tundra build interrupted (108.20 seconds - 0:01:48), 4 items updated, 429 evaluated
Internal build system error. Backend exited with code 1.

Symbol file LoadedFromMemory doesn’t match image F:\Unity\Project\Library\PackageCache\com.unity.visualscripting@1.7.8\Editor\VisualScripting.Core\Dependencies\DotNetZip\Unity.VisualScripting.IonicZip.dll
Native extension for WindowsStandalone target not found
Native extension for WebGL target not found

CompileScripts: 106371.468ms

Not sure exactly what these mean, but it seems like it is the actual compilation itself that is getting caught up.

Nope. I run other higher-demand applications like Blender, Photoshop, Inventor, etc and have no issues. I’ve also compiled MonoGame projects within visual studio with no issues.

Have you tried deleting the Library folder?

And if you don’t use Visual Scripting, remove that package.