Ticket #45 (closed defect: fixed)

Opened 4 years ago

Last modified 2 years ago

Multiple Attributes Cause Slow Performance

Reported by: bpelton@… Owned by: rauchy
Priority: normal Milestone:
Component: Code Layout Version:
Severity: normal Keywords: performance
Cc:

Description

Originally asked here:  http://www.rauchy.net/regionerate/forums/viewtopic.php?f=6&t=181

Having multiple attributes causes significant delay in regionerating classes.

A simple test is:

namespace MyApp.Core.Entities
{
  class Test
  {
    [Obsolete]
    [Obsolete]
    [Obsolete]
    [Obsolete]
    [Obsolete]
    [Obsolete]
    [Obsolete]
    [Obsolete]
    [Obsolete]
    public object A
    {
      get { return "A"; }
    }
  }
}

The layout does not seem to be the issue as it occurs with various layouts and the default layout.

Change History

Changed 3 years ago by bpelton@…

I'm back to working on this project and stumbled into this bug again. This time I decided to try and narrow down the problem and maybe even fix it, but...

When I step through the regionerate code, the regex match seems to be the bottleneck.

I can't get my head around the regex's used to parse the code, so I think I'm stuck waiting for rauchy to fix this.

Changed 3 years ago by bpelton@…

This is a shot in the dark, but...

The regex looks to be splitting out the relevant parts into groups (comments, attributes, access, etc..), but perhaps it would speed things up to use two sets of regexes, the first set would be simple and just look for the item, and then it would be used to identify the correct Code Builder.

Basically, instead of looping through the "complex" regexes, loop through some "simplified" regexs that identify Classes, or Properties or Methods, and then step two is to apply the specific "complex" regex.

I will perform some code timings to see if this would help or not.

Changed 3 years ago by rauchy

Splitting the regex patterns is a good idea. It would require a big refactoring job, but it might do the job.

Let me know if your tests show that this might be the solution for the problem.

Thanks.

Changed 3 years ago by bpelton@…

In my testing, I found that the slow part was the MethodBuilder? CodeBuilder?. So, I modified CodeBuilderFactory? and put the Add for PropertyBuilder? first, (since properties are where I have multiple attributes), then MethodBuilder?.

This is a work-around, but it gets me moving again. I don't have NUnit installed so I couldn't run the tests to see if I broke anything by changing that. Running against my code base didn't cause any errors that I could find. The code still compiles successfully and all of my unit tests still succeed. (I use MSTest).

Based on this, I don't think splitting the regex into "simple" and "complex" is necessary at this point. I would think some investigation into the Regex Pattern for MethodBuilder? might be a better investment of time, but I'm not very familiar with writing regexs.

Changed 3 years ago by jan

I implemented the suggested solution from bpelton and was able to run all nunit tests succesfully.

I also added the RegexOptions?.Compiled option to the regular expressions in the following places: CodeBuilder?.cs protected constructor CodeStreamReader?.cs public constructor

However these last 2 modifications did not have the impact acchieved by moving the PropertyBuilder? to the first entry.

Changed 3 years ago by rauchy

jan & bpelton,

Based on your personal experience, do you find yourself attributing properties more often than methods? and do you think that moving PropertyBuilder? to the first entry is the best work-around at the moment?

This would probably make things slow for those who have lots of attributes on methods.

Changed 3 years ago by bpelton@…

Agree that I'm just shifting the problem, but in my particular project there's a heavy usage of attributes for properties (properties of Entity classes, specifically) and not so much for methods.

There might be other projects where there is a heavy usage of attributes for methods. (Something like WCF? Just guessing.)

Here is my real-life example of a property with multiple attributes:

        /// <summary>
        /// Gets or sets the display name for the user.
        /// </summary>
        [SearchField(0)]
        [ListField(1)]
        [FieldDescription("Display name", "Name")]
        [StringLengthValidator(4, 50)]
        [NotNullValidator]
        public virtual string DisplayName
        {
            get { return _displayName; }
            set
            {
                _displayName = value.Trim();
                NotifyPropertyChanged("DisplayName");
            }
        }

These attributes are used to provide validation rules and also search options. These are things I need to use for methods.

Changed 3 years ago by bpelton@…

Ack... I meant:

These are things I don't need to use for methods.

Changed 3 years ago by rauchy

I think it might be time to merge that patch into the trunk. There are a couple of months left until we release 0.7.5, so we will get enough feedback from our users, if any problems occurs from this change.

Can anyone please send me a patch to omer at rauchy d0t net?

Changed 2 years ago by bpelton@…

Do you still need a patch for this?

Changed 2 years ago by rauchy

Yeah, can you send it?

From what I remember, its a pretty trivial patch, right?

Changed 2 years ago by bpelton@…

Yeah pretty trivial - just reorders the builders in the CodeBuilderFactory?. This is the patch, and I'll email it as well:

Index: CodeBuilderFactory.cs
===================================================================
--- CodeBuilderFactory.cs	(revision 392)
+++ CodeBuilderFactory.cs	(working copy)
@@ -56,8 +56,8 @@
                     _builders.Add( new InterfaceBuilder() );
                     break;
                 case ConstructionContext.Type:
+                    _builders.Add( new PropertyBuilder() );
                     _builders.Add( new MethodBuilder() );
-                    _builders.Add( new PropertyBuilder() );
                     _builders.Add( new EventBuilder() );
                     _builders.Add( new FieldBuilder() );
                     _builders.Add( new EnumCodeBuilder() );

Changed 2 years ago by rauchy

  • status changed from new to closed
  • resolution set to fixed

(In [393]) Fixes #45. Sort of :-) Submitted by Brian Pelton.

Changed 2 years ago by anonymous

Buy Steroids Online Steroid for sale : oral (for steroids in pill form), injectable steroids for sale, and transdermal. Oral steroids for sale administration, while perhaps the most convenient, suffers from the fact that oral steroids need to be chemically modified, and their metabolism into the active form can place strain on the liver.

 http://www.roidsmall.net/oral-steroids-sale-508/ Oral Steroids Sale  http://www.roidsmall.net/injectable-steroids-sale-509/ Injectable Steroids Sale  http://www.roidsmall.net/injectable-steroids-sachets-510/ Injectable Steroids Sachets

Note: See TracTickets for help on using tickets.