New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added API to provide mutiple regex patterns for enumerating files. #922

Merged
merged 17 commits into from Jul 14, 2017

Conversation

Projects
None yet
4 participants
@harshjain2
Member

harshjain2 commented Jul 11, 2017

Added API to provide mutiple regex patterns for enumerating files.
This should give perf benefit as Directory.EnumerateFiles is called only once and files names are matched using multiple regex patterns.

It is bound to give an improvement of around 5-8%

Show outdated Hide outdated src/Microsoft.TestPlatform.Client/TestPlatform.cs
var extensionAssemblies = new List<string>(this.fileHelper.EnumerateFiles(adapterPath, patterns, SearchOption.AllDirectories));

This comment has been minimized.

@codito

codito Jul 11, 2017

Contributor

Not sure if the responsibility to combine and create a regex should be with EnumerateFiles.

@codito

codito Jul 11, 2017

Contributor

Not sure if the responsibility to combine and create a regex should be with EnumerateFiles.

Show outdated Hide outdated src/Microsoft.TestPlatform.Client/TestPlatform.cs
extensionAssemblies.AddRange(this.fileHelper.EnumerateFiles(adapterPath, TestPlatformConstants.TestLoggerRegexPattern, SearchOption.AllDirectories));
extensionAssemblies.AddRange(this.fileHelper.EnumerateFiles(adapterPath, TestPlatformConstants.RunTimeRegexPattern, SearchOption.AllDirectories));
extensionAssemblies.AddRange(this.fileHelper.EnumerateFiles(adapterPath, TestPlatformConstants.SettingsProviderRegexPattern, SearchOption.AllDirectories));
var patterns = new string[] { TestPlatformConstants.TestAdapterRegexPattern, TestPlatformConstants.TestLoggerRegexPattern, TestPlatformConstants.RunTimeRegexPattern, TestPlatformConstants.SettingsProviderRegexPattern };

This comment has been minimized.

@codito

codito Jul 11, 2017

Contributor

If all these patterns are known why not Regex.Compile it directly in this class. We will save some time during runtime?

@codito

codito Jul 11, 2017

Contributor

If all these patterns are known why not Regex.Compile it directly in this class. We will save some time during runtime?

@codito

Suggest few changes.

@AbhitejJohn

This comment has been minimized.

Show comment
Hide comment
@AbhitejJohn

AbhitejJohn Jul 12, 2017

Member

quick question: How much of a perf benefit did this net us? Just curious.

Member

AbhitejJohn commented Jul 12, 2017

quick question: How much of a perf benefit did this net us? Just curious.

Show outdated Hide outdated src/Microsoft.TestPlatform.Client/TestPlatform.cs
extensionAssemblies.AddRange(this.fileHelper.EnumerateFiles(adapterPath, TestPlatformConstants.RunTimeRegexPattern, SearchOption.AllDirectories));
extensionAssemblies.AddRange(this.fileHelper.EnumerateFiles(adapterPath, TestPlatformConstants.SettingsProviderRegexPattern, SearchOption.AllDirectories));
var patterns = new string[] { TestPlatformConstants.TestAdapterRegexPattern, TestPlatformConstants.TestLoggerRegexPattern, TestPlatformConstants.RunTimeRegexPattern, TestPlatformConstants.SettingsProviderRegexPattern };

This comment has been minimized.

@codito

codito Jul 12, 2017

Contributor

nit: runtime is one word

@codito

codito Jul 12, 2017

Contributor

nit: runtime is one word

Show outdated Hide outdated src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManager.cs
@@ -184,8 +184,7 @@ private void InitializeExtensions(IEnumerable<string> sources)
if (TestPluginCache.Instance.PathToExtensions != null)
{
var regex = new Regex(TestPlatformConstants.TestAdapterRegexPattern, RegexOptions.IgnoreCase);
extensions.AddRange(TestPluginCache.Instance.PathToExtensions.Where(ext => regex.IsMatch(ext)));
extensions.AddRange(TestPluginCache.Instance.PathToExtensions.Where(ext => TestExecutorExtensionManager.Regex.IsMatch(ext)));

This comment has been minimized.

@codito

codito Jul 12, 2017

Contributor

Should these be different regular expression than the discovery one?

@codito

codito Jul 12, 2017

Contributor

Should these be different regular expression than the discovery one?

Show outdated Hide outdated ...TestPlatform.Common/ExtensionFramework/DataCollectionExtensionManager.cs
@@ -17,6 +18,8 @@ namespace Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework
/// </summary>
internal class DataCollectorExtensionManager : TestExtensionManager<DataCollector, IDataCollectorCapabilities>
{
public static Regex Regex = new Regex(TestPlatformConstants.DataCollectorRegexPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);

This comment has been minimized.

@codito

codito Jul 12, 2017

Contributor

nit: can be more specific name?

@codito

codito Jul 12, 2017

Contributor

nit: can be more specific name?

Show outdated Hide outdated src/Microsoft.TestPlatform.Client/TestPlatform.cs
extensionAssemblies.AddRange(this.fileHelper.EnumerateFiles(adapterPath, TestPlatformConstants.RunTimeRegexPattern, SearchOption.AllDirectories));
extensionAssemblies.AddRange(this.fileHelper.EnumerateFiles(adapterPath, TestPlatformConstants.SettingsProviderRegexPattern, SearchOption.AllDirectories));
var patterns = new string[] { TestPlatformConstants.TestAdapterRegexPattern, TestPlatformConstants.TestLoggerRegexPattern, TestPlatformConstants.RunTimeRegexPattern, TestPlatformConstants.SettingsProviderRegexPattern };

This comment has been minimized.

@codito

codito Jul 12, 2017

Contributor

Most of the patterns are compatible with string.EndsWith. Do we know how does string comparison compare with regex? Is there any observable startup time impact in regex compiled?

@codito

codito Jul 12, 2017

Contributor

Most of the patterns are compatible with string.EndsWith. Do we know how does string comparison compare with regex? Is there any observable startup time impact in regex compiled?

This comment has been minimized.

@harshjain2

harshjain2 Jul 14, 2017

Member

On measuring perf, it is observed that String.EndsWith performs better than Regex, therefore switched to String.EndsWith approach.

@harshjain2

harshjain2 Jul 14, 2017

Member

On measuring perf, it is observed that String.EndsWith performs better than Regex, therefore switched to String.EndsWith approach.

@codito

codito approved these changes Jul 14, 2017

@harshjain2 harshjain2 merged commit e9a708b into Microsoft:master Jul 14, 2017

4 checks passed

Ubuntu16.04 / Debug Build Build finished.
Details
Ubuntu16.04 / Release Build Build finished.
Details
Windows_NT / Debug Build Build finished.
Details
Windows_NT / Release Build Build finished.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment