FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Improve cache for match, split, replace operators and WildcardPattern by iSazonov · Pull Request #10657 · PowerShell/PowerShell · GitHub

Improve cache for match, split, replace operators and WildcardPattern - #10657

Merged
Dongbo Wang (daxian-dbw) merged 7 commits into
PowerShell:masterfrom
iSazonov:perf-cmatch-add-cache
Nov 1, 2019
Merged

Improve cache for match, split, replace operators and WildcardPattern#10657
Dongbo Wang (daxian-dbw) merged 7 commits into
PowerShell:masterfrom
iSazonov:perf-cmatch-add-cache

Conversation

Ilya (iSazonov) commented Oct 1, 2019
edited
Loading

Copy link
Copy Markdown
Collaborator

PR Summary

Fix #8941

  • Add new cache for case-sensitive Regex-s
  • Use StringComparer.Ordinal in the cache (that will slightly speed up and reduce allocations)
  • Use the cache in regex.cs (that will slightly speed up cmdlets)
  • Make the cache two-level to take in account all regex option combinations.

PR Context

Before the change we cached only case-insensitive Regex-s (with RegexOptions.IgnoreCase).

PR Checklist

Ilya (iSazonov) added the CL-Performance Indicates that a PR should be marked as a performance improvement in the Change Log label Oct 1, 2019
Ilya (iSazonov) added this to the 7.0.0-preview.5 milestone Oct 1, 2019
Ilya (iSazonov) changed the title Improve cache for match, split and replace operators and WildcardPattern Improve cache for match, split, replace operators and WildcardPattern Oct 1, 2019

Copy link
Copy Markdown
Collaborator Author

/cc Michael Klement (@mklement0) if you are interested to see and measure results.

ghost added Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept and removed Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept labels Oct 1, 2019
}
else
{
return subordinateRegexCache.GetOrAdd(patternString, key =>

Dongbo Wang (daxian-dbw) Oct 31, 2019
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Having this lambda expression in this method will result in an instance of the helper class to be created every time NewRegex gets called, even if the query can be served by the cache.

This should be changed to the following:

else
{
    if (subordinateRegexCache.Count > MaxRegexCache)
    {
        subordinateRegexCache.Clear();
    }

    var regex = new Regex(patternString, options);
    return subordinateRegexCache.GetOrAdd(patternString, regex);
}

Note that, the ValueFactory delegate is called outside the locks and thus it's not atomic, meaning there is no difference clearing the dictionary this way from doing it in the ValueFactory delegate.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks for great comment!

Done.

ghost added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Oct 31, 2019
ghost removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Nov 1, 2019

Dongbo Wang (daxian-dbw) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM

Dongbo Wang (daxian-dbw) merged commit 54edaee into PowerShell:master Nov 1, 2019
Ilya (iSazonov) deleted the perf-cmatch-add-cache branch November 1, 2019 18:28

Copy link
Copy Markdown

🎉v7.0.0-preview.6 has been released which incorporates this pull request.:tada:

Handy links:

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-Performance Indicates that a PR should be marked as a performance improvement in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Performance problem: -cmatch prevents automatic caching of on-demand-compiled regexes

4 participants


Back | FazBrowse Home | New Git URL