KEMBAR78
Shave ~90K off regex in native aot by stephentoub · Pull Request #80884 · dotnet/runtime · GitHub
Skip to content

Conversation

stephentoub
Copy link
Member

  • ifdef out some code only used in debug but that included a static which was rooting some of the methods
  • Avoid using a ValueTuple`7 as a dictionary key and instead use a custom struct
  • Remove a Sort call that was leftover from debugging but isn't necessary for correctness or performance
  • Avoid using a HashSet<UnicodeCategory> when a bool[30] would suffice
  • Avoid a generic instantation for a Dictionary<enum,object,object> by changing it to Dictionary<int,object,object>, which we already use in the same type

This:

using System.Text.RegularExpressions;

internal class Program
{
    static void Main()
    {
        Console.WriteLine(new Regex("a", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase).IsMatch("abc"));
    }
}

published for Windows x64 native aot drops from 3618K to 3529K.

- ifdef out some code only used in debug but that included a static which was rooting some of the methods
- Avoid using a ValueTuple`7 as a dictionary key and instead use a custom struct
- Remove a Sort call that was leftover from debugging but isn't necessary for correctness or performance
- Avoid using a `HashSet<UnicodeCategory>` when a `bool[30]` would suffice
- Avoid a generic instantation for a `Dictionary<enum,object,object>` by changing it to `Dictionary<int,object,object>`, which we already use in the same type
@ghost
Copy link

ghost commented Jan 19, 2023

Tagging subscribers to this area: @dotnet/area-system-text-regularexpressions
See info in area-owners.md if you want to be subscribed.

Issue Details
  • ifdef out some code only used in debug but that included a static which was rooting some of the methods
  • Avoid using a ValueTuple`7 as a dictionary key and instead use a custom struct
  • Remove a Sort call that was leftover from debugging but isn't necessary for correctness or performance
  • Avoid using a HashSet<UnicodeCategory> when a bool[30] would suffice
  • Avoid a generic instantation for a Dictionary<enum,object,object> by changing it to Dictionary<int,object,object>, which we already use in the same type

This:

using System.Text.RegularExpressions;

internal class Program
{
    static void Main()
    {
        Console.WriteLine(new Regex("a", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase).IsMatch("abc"));
    }
}

published for Windows x64 native aot drops from 3618K to 3529K.

Author: stephentoub
Assignees: stephentoub
Labels:

area-System.Text.RegularExpressions

Milestone: -

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

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

This is great!

LGTM. Thanks

@EgorBo
Copy link
Member

EgorBo commented Jan 20, 2023

Avoid using a ValueTuple`7 as a dictionary key and instead use a custom struct

Sounds like #76513?

@marek-safar marek-safar added the size-reduction Issues impacting final app size primary for size sensitive workloads label Jan 20, 2023
@ghost
Copy link

ghost commented Jan 20, 2023

Tagging subscribers to 'size-reduction': @eerhardt, @SamMonoRT, @marek-safar
See info in area-owners.md if you want to be subscribed.

Issue Details
  • ifdef out some code only used in debug but that included a static which was rooting some of the methods
  • Avoid using a ValueTuple`7 as a dictionary key and instead use a custom struct
  • Remove a Sort call that was leftover from debugging but isn't necessary for correctness or performance
  • Avoid using a HashSet<UnicodeCategory> when a bool[30] would suffice
  • Avoid a generic instantation for a Dictionary<enum,object,object> by changing it to Dictionary<int,object,object>, which we already use in the same type

This:

using System.Text.RegularExpressions;

internal class Program
{
    static void Main()
    {
        Console.WriteLine(new Regex("a", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase).IsMatch("abc"));
    }
}

published for Windows x64 native aot drops from 3618K to 3529K.

Author: stephentoub
Assignees: stephentoub
Labels:

area-System.Text.RegularExpressions, size-reduction

Milestone: -

@stephentoub stephentoub merged commit 1c8b2de into dotnet:main Jan 20, 2023
@stephentoub stephentoub deleted the trimregex branch January 20, 2023 12:33
mdh1418 pushed a commit to mdh1418/runtime that referenced this pull request Jan 24, 2023
* Shave ~100K off regex in native aot

- ifdef out some code only used in debug but that included a static which was rooting some of the methods
- Avoid using a ValueTuple`7 as a dictionary key and instead use a custom struct
- Remove a Sort call that was leftover from debugging but isn't necessary for correctness or performance
- Avoid using a `HashSet<UnicodeCategory>` when a `bool[30]` would suffice
- Avoid a generic instantation for a `Dictionary<enum,object,object>` by changing it to `Dictionary<int,object,object>`, which we already use in the same type

* Address PR feedback
@ghost ghost locked as resolved and limited conversation to collaborators Feb 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Text.RegularExpressions size-reduction Issues impacting final app size primary for size sensitive workloads

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants