Skip to content
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

ResponseTransformer slow for large pages #263

Open
jeremycampbellaustin opened this issue May 15, 2014 · 0 comments
Open

ResponseTransformer slow for large pages #263

jeremycampbellaustin opened this issue May 15, 2014 · 0 comments

Comments

@jeremycampbellaustin
Copy link

I changed this loop:

var result = preTransform;
foreach (var match in transformableMatches)
{
var idx = result.IndexOf(match, StringComparison.Ordinal);
result = result.Remove(idx, match.Length);
if(idx == result.Length)
continue;
if(result[idx] == '\r')
result = result.Remove(idx, 1);
if (result[idx] == '\n')
result = result.Remove(idx, 1);
}
return result;

To this loop:
StringBuilder resultNew = new StringBuilder();
using (StringReader stringReader = new StringReader(preTransform))
{
string line;
while ((line = stringReader.ReadLine()) != null)
{
if (!Filtered(transformableMatches, line))
{
resultNew.AppendLine(line);
}
}
}
return resultNew.ToString();

private bool Filtered(List transformableMatches, string line)
{
int indexOf = -1;
for(int i = 0; i < transformableMatches.Count; ++i)
{
if (line.Contains(transformableMatches[i]))
{
indexOf = i;
break;
}
}

        return indexOf >= 0;
    }

Also this line:
preTransform = preTransform.Insert(insertionIdx + 1, resource.TransformedMarkupTag(transform));

To this line:
preTransform = preTransform.Insert(insertionIdx + 1, String.Format("{0}{1}", resource.TransformedMarkupTag(transform), Environment.NewLine));

Server processing time went from ~10sec to less than 1sec.

If someone peer programs with me and shows me the ropes, how to run the tests, etc. I will update the source.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant