Hi,

I understand the nature of your problem, but I if you are speaking about CAS I think it is not a so big problem. SRE is intended to access non-public members as well as public members. When enabling security ReflectionPermission controls whether code can access private members of other assemblies but this should not be a problem as I18N is part of the class library so it can have FullTrust without problems. Problems may occur in case of executable like mcs.exe but when signing them and granting them FullTrust based on public key there should not be problems. Of course granting full trust to a public key whose private key is public may may imply security problems but this could be solved by restricting the scope of this key to the directories of Mono.

Note that I attached a corrected patch because the previous one ignored the index parameter by mistake.

Some performance tests:

Before:
length, conversion: time
1, byte[]: 11578
1, byte[] int int: 12282
4, byte[]: 12609
4, byte[] int int: 12687
1024, byte[]: 37125
1024, byte[] int int: 37844
1048576, byte[]: 23875
1048576, byte[] int int: 24125

After:
length, conversion: time
1, byte[]: 3235
1, byte[] int int: 3203
4, byte[]: 3734
4, byte[] int int: 3797
1024, byte[]: 13297
1024, byte[] int int: 13234
1048576, byte[]: 5937
1048576, byte[] int int: 5844

The test program is attached.

Kornél

----- Original Message ----- From: "Miguel de Icaza" <[EMAIL PROTECTED]>
To: "Kornél Pál" <[EMAIL PROTECTED]>
Cc: <[email protected]>
Sent: Wednesday, June 07, 2006 6:48 AM
Subject: Re: [Mono-dev] [PATCH] Speed up ByteEncoding.GetString()


Hello Kornel,

ByteEncoding.GetString() currently uses StringBuilder that is very slow. I
modified it to use InternalAllocateStr and unsafe code that makes is much
faster.

Please review and approve the patch.

Am not sure that poking at the internals and using InternalAllocateStr
is a good idea.   One possibility would be to use "Friend Assemblies",
although that is only supported in the 2.0 profile, not in 1.0.

Although today Mono does not enforce at runtime accessibility, this is
something that we intend to fix, which means that access to internal
methods will at some point broken.   So this would be one of those
things we would have to fix.

(Today we do violate this rule when using dynamic method invocation, and
we would have to find solutions for the places where we do).

Miguel.
using System;
using System.Globalization;
using System.Text;

namespace UnicodeEncodingPerformance
{
        internal class UnicodeEncodingPerformance
        {
                private static Encoding encoding;

                private static void Main(string[] args)
                {
                        encoding = Encoding.GetEncoding(1252);
                        Console.WriteLine("length, conversion: time");
                        Convert(1, 10000000);
                        Convert(4, 10000000);
                        Convert(1024, 1000000);
                        Convert(1048576, 1000);
                }

                private static void Convert(int length, int count)
                {
                        string s;
                        char[] c;
                        byte[] b;
                        DateTime startTime;

                        s = new string('x', length);
                        c = new char[length];
                        s.CopyTo(0, c, 0, length);
                        b = new byte[length];

                        startTime = DateTime.Now;
                        for (int index = 0; index < count; index++)
                                encoding.GetString(b);
                        WriteResult(length, "byte[]", startTime, DateTime.Now);

                        startTime = DateTime.Now;
                        for (int index = 0; index < count; index++)
                                encoding.GetString(b, 0, length);
                        WriteResult(length, "byte[] int int", startTime, 
DateTime.Now);
                }

                private static void WriteResult(int length, string args, 
DateTime startTime, DateTime endTime)
                {
                        Console.WriteLine(length.ToString(CultureInfo.InvariantCulture) + ", 
" + args + ": " + 
((long)endTime.Subtract(startTime).TotalMilliseconds).ToString(CultureInfo.InvariantCulture));
                }
        }
}

Attachment: ByteEncoding.diff
Description: Binary data

_______________________________________________
Mono-devel-list mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to