[Mono-devel-list] [PATCH] Faster String.Equals
Andreas Nahr
ClassDevelopment at A-SoftTech.com
Sat May 22 06:38:55 EDT 2004
Hi,
first of all: Congrats to that speed gain ;)
However I see some problems with that approach:
1. Substantial code multiplication. We need Supported_Architectures + 1 code
implementations for every method instread of just 1. This will be horrible
to maintain and a lot of additional work.
2. Too platform specific optimizations. Look at your String.Equals that is
only implemented for x86. If somebody uses a lot of String.Equals in his own
classes then his implementation will perform seriously slower/ different on
other platforms. This may lead to problematic optimizations for classes
which internally use these methods.
3. Defeats the purpose of having a platform - neutralizing platform.
4. Although it does not have the overhead of an icall AFAIU it still poses a
problem for optimizations. A compiler (like ngen) may be able to completely
eliminate a case like:
"Test" != "Test"
to a false constant (very simple example). Is that still possible with your
implementation?
Or
String a = "dh"
String b = "dfh"
a.Equals (b)
might get inlined and *optimized* by the compiler or JIT or especially AOT
because it can guarantee that a and b can never be null (which is checked in
Equals).
5. A compiler tries (should try) to optimize to the maximum global speed,
you optimize for a maximum local speed which MIGHT lead to slower overall
performance (surely not nowadays because our compilers are not anywhere near
that level of optimization)
6. We still need a fast managed implementation for cases when a ASM -
version is not available
7. Finding bugs will be much harder if we have architecture specific
implementations for specific methods.
Therefore IMHO we should:
1. Add that ASM - injection architecture, but not enable it by default. We
could have a --AsmInject switch which enables it.
2. I would love to see a asm - coded version of string CreateString (int
length) :-)
I've attached my version of String.Equals which is also a lot faster than
the current version (especially for larger compares)
Microbench:
chars 7: 4196 -> 3054
chars 88: 2743 -> 1772
chars a lot: 1011 -> 591
Andreas
----- Original Message -----
From: "Ben Maurer" <bmaurer at users.sourceforge.net>
To: "Mono Development" <mono-devel-list at lists.ximian.com>
Sent: Saturday, May 22, 2004 3:46 AM
Subject: [Mono-devel-list] [PATCH] Faster String.Equals
> Hello,
>
> I have written a faster version of String.Equals. What I did was to hand
> code the method in assembly, and allow the JIT to inject the hand tuned
> code in place of the code that would be jitted.
>
> I also had to make some changes to arch/x86 to allow me to write the
> code I needed.
>
> The patch is attached.
>
> -- Ben
>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: PatchStringEquals.txt
Url: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20040522/130d0587/attachment.txt
More information about the Mono-devel-list
mailing list