Skip to content

TPA list building is contributing large % of time to startup #44545

@stephentoub

Description

@stephentoub

A runtime host is responsible for building up the TRUSTED_PLATFORM_ASSEMBLIES list that defines the assemblies the runtime should be able to resolve by default. To build up this list, all of our hosts are iterating through the relevant directories in the file system 4 times, one for each ".dll", ".ni.dll", ".exe", and ".ni.exe" extensions.

void AddFilesFromDirectoryToTPAList(_In_z_ const wchar_t* targetPath, _In_reads_(countExtensions) const wchar_t** rgTPAExtensions, int countExtensions)

HRESULT coreclr::CreateTpaList(_Inout_ std::string &tpaList, _In_opt_z_ const WCHAR *dir)

void AddFilesFromDirectoryToTpaList(const char* directory, std::string& tpaList)

void AddFilesFromDirectoryToTPAList(_In_z_ wchar_t* targetPath, _In_reads_(countExtensions) const wchar_t** rgTPAExtensions, int countExtensions)

But repeating such I/O four times is a very expensive way to do this, with cheaper ways to provide the same guarantee that the list is ordered the way we want with certain extensions preferred (e.g. just building up the list in a collection before serializing it to a string).

To validate this beyond profiles, I hacked up corerun's AddFilesFromDirectoryToTPAList to just iterate the directory once (with '*'), and the time to execute .\corerun helloworld.dll on my machine dropped from ~75ms to ~40ms.

We should in particular fix the production hosts to whatever extent they have the same problem.

cc: @brianrob, @DamianEdwards

Relates to #44598 and dotnet/msbuild#5876

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions