ResponseTransformer slow for large pages
Opened this issue · 0 comments
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.