Skip to content

Conversation

@Flamifly
Copy link

@Flamifly Flamifly commented Oct 18, 2025

I added the https://github.com/FenPhoenix/ReasonableRTF Project to be able to extract Text of RTF Files correctly.

  • Needed to implement multiple .Net Runtime Methods to be able to convert it to .Net Standard

I also upgraded the Tests to .Net 8 since .Net 6 is not supported anymore

  • Updated NUnit to the Newest Version and fixed Assers

I updated the Nugets if possible (NPOI seems to work different with 2.7.5 because the some Tests fails)

  • changed the IsTrue Method to IsEqual to gain better Performance

Tested Code:

public void Run()
{
    for (int i = 0; i < 1_000_000; i++)
    {
        IsTrue("1");
        IsTrue("0");
        IsTrue("on");
        IsTrue("off");
        IsTrue("true");
        IsTrue("false");
    }
}
public void Run2()
{
    for (int i = 0; i < 1_000_000; i++)
    {
        IsTrue2("1");
        IsTrue2("0");
        IsTrue2("on");
        IsTrue2("off");
        IsTrue2("true");
        IsTrue2("false");
    }
}

public static bool IsTrue(string sValue)
{
    sValue = sValue.ToLower();
    return (sValue == "1" || sValue == "on" || sValue == "true");
}

public static bool IsTrue2(string sValue)
{
    return (sValue.Equals("1", StringComparison.OrdinalIgnoreCase)) || (sValue.Equals("on", StringComparison.OrdinalIgnoreCase)) || (sValue.Equals("true", StringComparison.OrdinalIgnoreCase));
}

Result:
image

Changed the Comparer for the parserMapping Dictionary in the ParserFactory. The Keys will be checked caseinsensitiv to avoid allocations.

@Flamifly
Copy link
Author

I checked the differences between .Net Standard 2.0 and 2.1 and need to turn it back sorry did not know that it won't support Framework.

I will open a new one if I ported it to 2.0

@Flamifly Flamifly closed this Oct 18, 2025
@Flamifly Flamifly reopened this Oct 18, 2025
@Flamifly
Copy link
Author

Changed Framework back to .Net Standard 2.0

The Change to the RTF Library is a huge improvement the performance difference is crazy.

Note: The new Method extracts the Text 10 times while the old implementation does it once. The Test File was a ~15MB RTF File for both Tests, I duplicated it because I wasn't sure if the Tests will ran multithreaded.
Tested:

private static readonly Toxy.ParserContext context = new Toxy.ParserContext(fileName);
private static readonly Toxy.ParserContext context2 = new Toxy.ParserContext(fileName2);

public void Run()
{
    ToxyFramework.Parsers.RTFTextParser parser = new ToxyFramework.Parsers.RTFTextParser(context);
    for (int i = 0; i < 10; i++)
    {
        parser.Parse();
    }
}
public void Run2()
{
    ToxyFramework.Parsers.RTFTextParser parser = new ToxyFramework.Parsers.RTFTextParser(context2);
    parser.Parse2();
}

Result:
image

As you can see the allocations are more than 11GB less and the take more than 22secs time.

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

Successfully merging this pull request may close these issues.

1 participant