Skip to content

Commit

Permalink
Optimize function lookup (microsoft#1019)
Browse files Browse the repository at this point in the history
Store functions in optimized TexlFunctionSet<TexlFunction> object
instead of IEnumerable<TextFunction>

Benchmark results
- -61% for Check N=1
- -77% for Check N=5
- -79% for Check N=10
- -42% for Eval N=1
- -65% for Eval N=5
- -67% for Eval N=10

Negligible improvement for Parse , Tokenize or PVA* benchmarks
  • Loading branch information
LucGenetier authored Feb 23, 2023
1 parent 83e3f81 commit 341a621
Show file tree
Hide file tree
Showing 41 changed files with 1,219 additions and 505 deletions.
2 changes: 1 addition & 1 deletion .scripts/WriteBenchmark.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ $list = (Get-Item -Filter *.csv -Path '.\BenchmarkDotNet.Artifacts\results\*' |
foreach ($file in [System.Linq.Enumerable]::OrderBy($list, [Func[object, string]] { param($s) if ($s -match 'Reference-report\.csv') { "" } else { $s } }))
{
$t = [System.IO.Path]::GetFileNameWithoutExtension($file).Split(@('.'))[-1]
$testCategory = $t.Substring(0, $t.Length - 7)
if ($t.Length -gt 7) { $testCategory = $t.Substring(0, $t.Length - 7) } else { $testCategory = $t }

Write-Host "------ [TEST] $testCategory ------"

Expand Down
7 changes: 7 additions & 0 deletions src/Microsoft.PowerFx.sln
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.PowerFx.Json", "l
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.PowerFx.Json.Tests", "tests\Microsoft.PowerFx.Json.Tests\Microsoft.PowerFx.Json.Tests.csproj", "{8986E836-2F55-4D71-B23E-50F4A8427A5B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Benchmark", "Benchmark", "{89514D49-4D5D-4423-A6EC-F0FF1D23EF43}"
ProjectSection(SolutionItems) = preProject
ReadBenchmarkData.ps1 = ReadBenchmarkData.ps1
..\.scripts\WriteBenchmark.ps1 = ..\.scripts\WriteBenchmark.ps1
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -128,6 +134,7 @@ Global
{142854D7-409C-4C87-A5B8-39B51477F5B2} = {5EEC2873-35B5-4364-A2A0-97AAD7BF960D}
{D4CC6660-8C30-41E5-A28A-C018DDDF8D96} = {4269F3C3-6B42-419B-B64A-3E6DC0F1574A}
{8986E836-2F55-4D71-B23E-50F4A8427A5B} = {AD743B78-D61F-4FBF-B620-FA83CE599A50}
{89514D49-4D5D-4423-A6EC-F0FF1D23EF43} = {4269F3C3-6B42-419B-B64A-3E6DC0F1574A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {30372F91-B206-4351-A621-F0E2773C337B}
Expand Down
4 changes: 2 additions & 2 deletions src/ReadBenchmarkData.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function ConvertToMs([string]$str)
## Convert to milliseconds
if ($parts[1] -eq "s") { $val *= 1000 }
elseif ($parts[1] -eq "ms") { } ## Do nothing
elseif ($parts[1] -eq "µs") { $val /= 1000 }
elseif ($parts[1] -eq "μs") { $val /= 1000 }
elseif ($parts[1] -eq "ns") { $val /= 1000000 }
else { throw ("Unknown unit: " + $parts[1]) }
}
Expand Down Expand Up @@ -172,7 +172,7 @@ $list = (Get-Item -Filter *.csv -Path '.\BenchmarkDotNet.Artifacts\results\*' |
foreach ($file in [System.Linq.Enumerable]::OrderBy($list, [Func[object, string]] { param($s) if ($s -match 'Reference-report\.csv') { "" } else { $s } }))
{
$t = [System.IO.Path]::GetFileNameWithoutExtension($file).Split(@('.'))[-1]
$testCategory = $t.Substring(0, $t.Length - 7)
if ($t.Length -gt 7) { $testCategory = $t.Substring(0, $t.Length - 7) } else { $testCategory = $t }

Write-Host "------ [TEST] $testCategory ------"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal interface INameResolver

DPath CurrentEntityPath { get; }

IEnumerable<TexlFunction> Functions { get; }
TexlFunctionSet Functions { get; }

// This advertises whether the INameResolver instance will suggest unqualified enums ("Hours")
// or only qualified enums ("TimeUnit.Hours").
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.PowerFx.Core.App.ErrorContainers;
using Microsoft.PowerFx.Core.Binding;
using Microsoft.PowerFx.Core.Entities;
Expand All @@ -27,7 +25,6 @@
using Microsoft.PowerFx.Core.Types;
using Microsoft.PowerFx.Core.Utils;
using Microsoft.PowerFx.Syntax;
using Microsoft.PowerFx.Types;
using static Microsoft.PowerFx.Core.IR.IRTranslator;
using CallNode = Microsoft.PowerFx.Syntax.CallNode;
using IRCallNode = Microsoft.PowerFx.Core.IR.Nodes.CallNode;
Expand Down Expand Up @@ -362,7 +359,7 @@ public TexlFunction(
// This can be used to generate a list of enums required for a function library.
public virtual IEnumerable<string> GetRequiredEnumNames()
{
return new List<string>();
return Enumerable.Empty<string>();
}

// Return all signatures with at most 'arity' parameters.
Expand Down

This file was deleted.

Loading

0 comments on commit 341a621

Please sign in to comment.