Skip to content

Commit 96ab036

Browse files
committed
In JsRT modes improved a performance of .NET methods projection
1 parent 4856631 commit 96ab036

File tree

5 files changed

+36
-14
lines changed

5 files changed

+36
-14
lines changed

src/MsieJavaScriptEngine/JsRt/Edge/EdgeTypeMapper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,12 +573,12 @@ private void ProjectMethods(EdgeEmbeddedItem externalItem)
573573
string typeName = type.FullName;
574574
BindingFlags defaultBindingFlags = ReflectionHelpers.GetDefaultBindingFlags(instance);
575575
MethodInfo[] methods = type.GetMethods(defaultBindingFlags);
576-
IEnumerable<IGrouping<string, MethodInfo>> availableMethodGroups = GetAvailableMethodGroups(methods);
576+
Dictionary<string, List<MethodInfo>> availableMethodGroups = GetAvailableMethodGroups(methods);
577577

578-
foreach (IGrouping<string, MethodInfo> methodGroup in availableMethodGroups)
578+
foreach (KeyValuePair<string, List<MethodInfo>> methodGroup in availableMethodGroups)
579579
{
580580
string methodName = methodGroup.Key;
581-
MethodInfo[] methodCandidates = methodGroup.ToArray();
581+
MethodInfo[] methodCandidates = methodGroup.Value.ToArray();
582582

583583
EdgeJsNativeFunction nativeFunction = (callee, isConstructCall, args, argCount, callbackData) =>
584584
{

src/MsieJavaScriptEngine/JsRt/Ie/IeTypeMapper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,12 +573,12 @@ private void ProjectMethods(IeEmbeddedItem externalItem)
573573
string typeName = type.FullName;
574574
BindingFlags defaultBindingFlags = ReflectionHelpers.GetDefaultBindingFlags(instance);
575575
MethodInfo[] methods = type.GetMethods(defaultBindingFlags);
576-
IEnumerable<IGrouping<string, MethodInfo>> availableMethodGroups = GetAvailableMethodGroups(methods);
576+
Dictionary<string, List<MethodInfo>> availableMethodGroups = GetAvailableMethodGroups(methods);
577577

578-
foreach (IGrouping<string, MethodInfo> methodGroup in availableMethodGroups)
578+
foreach (KeyValuePair<string, List<MethodInfo>> methodGroup in availableMethodGroups)
579579
{
580580
string methodName = methodGroup.Key;
581-
MethodInfo[] methodCandidates = methodGroup.ToArray();
581+
MethodInfo[] methodCandidates = methodGroup.Value.ToArray();
582582

583583
IeJsNativeFunction nativeFunction = (callee, isConstructCall, args, argCount, callbackData) =>
584584
{

src/MsieJavaScriptEngine/JsRt/TypeMapper.cs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,37 @@ protected bool IsAvailableProperty(PropertyInfo property)
229229
return isAvailable;
230230
}
231231

232-
protected IEnumerable<IGrouping<string, MethodInfo>> GetAvailableMethodGroups(MethodInfo[] methods)
232+
protected Dictionary<string, List<MethodInfo>> GetAvailableMethodGroups(MethodInfo[] methods)
233233
{
234-
IEnumerable<MethodInfo> availableMethods = methods.Where(ReflectionHelpers.IsFullyFledgedMethod);
235-
if (!_allowReflection)
234+
int methodCount = methods.Length;
235+
if (methodCount == 0)
236236
{
237-
availableMethods = availableMethods.Where(ReflectionHelpers.IsAllowedMethod);
237+
return new Dictionary<string, List<MethodInfo>>();
238+
}
239+
240+
var availableMethodGroups = new Dictionary<string, List<MethodInfo>>(methodCount);
241+
242+
foreach (MethodInfo method in methods)
243+
{
244+
if (!ReflectionHelpers.IsFullyFledgedMethod(method)
245+
|| (!_allowReflection && !ReflectionHelpers.IsAllowedMethod(method)))
246+
{
247+
continue;
248+
}
249+
250+
string methodName = method.Name;
251+
List<MethodInfo> methodGroup;
252+
253+
if (availableMethodGroups.TryGetValue(methodName, out methodGroup))
254+
{
255+
methodGroup.Add(method);
256+
}
257+
else
258+
{
259+
methodGroup = new List<MethodInfo> { method };
260+
availableMethodGroups.Add(methodName, methodGroup);
261+
}
238262
}
239-
IEnumerable<IGrouping<string, MethodInfo>> availableMethodGroups = availableMethods.GroupBy(m => m.Name);
240263

241264
return availableMethodGroups;
242265
}

src/MsieJavaScriptEngine/MsieJavaScriptEngine.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<IncludeSymbols>true</IncludeSymbols>
2626
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
2727
<PackageTags>JavaScript;ECMAScript;MSIE;IE;Edge;Chakra</PackageTags>
28-
<PackageReleaseNotes>In JavaScript engine settings was added one new property - `AllowReflection` (default `false`).</PackageReleaseNotes>
28+
<PackageReleaseNotes>In JsRT modes improved a performance of .NET methods projection.</PackageReleaseNotes>
2929
<NeutralLanguage>en-US</NeutralLanguage>
3030
<PackageOutputPath>../../nuget</PackageOutputPath>
3131
<GeneratePackageOnBuild Condition=" '$(Configuration)' == 'Release' ">true</GeneratePackageOnBuild>

src/MsieJavaScriptEngine/readme.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
=============
2222
RELEASE NOTES
2323
=============
24-
In JavaScript engine settings was added one new property - `AllowReflection`
25-
(default `false`).
24+
In JsRT modes improved a performance of .NET methods projection.
2625

2726
============
2827
PROJECT SITE

0 commit comments

Comments
 (0)