Skip to content

ResponseTransformer slow for large pages #263

@jeremycampbellaustin

Description

@jeremycampbellaustin

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions