Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using ArrayPool for AssocTable #8234

Merged
merged 4 commits into from Jan 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions eng/Versions.props
Expand Up @@ -95,6 +95,7 @@
<SystemThreadingThreadVersion>4.3.0</SystemThreadingThreadVersion>
<SystemThreadingThreadPoolVersion>4.3.0</SystemThreadingThreadPoolVersion>
<SystemValueTupleVersion>4.5.0</SystemValueTupleVersion>
<SystemBuffersVersion>4.5.0</SystemBuffersVersion>
<!-- Roslyn packages -->
<MicrosoftCodeAnalysisEditorFeaturesVersion>$(RoslynVersion)</MicrosoftCodeAnalysisEditorFeaturesVersion>
<MicrosoftCodeAnalysisEditorFeaturesTextVersion>$(RoslynVersion)</MicrosoftCodeAnalysisEditorFeaturesTextVersion>
Expand Down
1 change: 1 addition & 0 deletions fcs/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj
Expand Up @@ -680,6 +680,7 @@
<PackageReference Include="FSharp.Core" Version="$(FcsFSharpCorePkgVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="1.5.0" />
<PackageReference Include="System.Reflection.Metadata" Version="1.6.0" />
<PackageReference Include="System.Buffers" Version="4.5.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Diagnostics.Process" Version="4.1.0" />
Expand Down
Expand Up @@ -743,6 +743,7 @@
<PackageReference Include="System.Threading.Tasks.Parallel" Version="$(SystemThreadingTasksParallelVersion)" />
<PackageReference Include="System.Threading.Thread" Version="$(SystemThreadingThreadVersion)" />
<PackageReference Include="System.Threading.ThreadPool" Version="$(SystemThreadingThreadPoolVersion)" />
<PackageReference Include="System.Buffers" Version="$(SystemBuffersVersion)" />
</ItemGroup>

</Project>
24 changes: 17 additions & 7 deletions src/utils/prim-parsing.fs
Expand Up @@ -7,6 +7,7 @@ namespace Internal.Utilities.Text.Parsing
open Internal.Utilities.Text.Lexing

open System
open System.Buffers

exception RecoverableParseError
exception Accept of obj
Expand Down Expand Up @@ -131,11 +132,7 @@ module internal Implementation =
//-------------------------------------------------------------------------
// Read the tables written by FSYACC.

type AssocTable(elemTab:uint16[], offsetTab:uint16[]) =
let cacheSize = 7919 // the 1000'th prime
// Use a simpler hash table with faster lookup, but only one
// hash bucket per key.
let cache = Array.zeroCreate<int> (cacheSize * 2)
type AssocTable(elemTab: uint16[], offsetTab: uint16[], cache: int[], cacheSize: int) =

member t.ReadAssoc (minElemNum,maxElemNum,defaultValueOfAssoc,keyToFind) =
// do a binary chop on the table
Expand Down Expand Up @@ -234,8 +231,21 @@ module internal Implementation =
let ruleValues = (Array.zeroCreate 100 : obj[])
let lhsPos = (Array.zeroCreate 2 : Position[])
let reductions = tables.reductions
let actionTable = new AssocTable(tables.actionTableElements, tables.actionTableRowOffsets)
let gotoTable = new AssocTable(tables.gotos, tables.sparseGotoTableRowOffsets)
let cacheSize = 7919 // the 1000'th prime
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol what?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea :) - I just copied what was there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair enough

// Use a simpler hash table with faster lookup, but only one
// hash bucket per key.
let actionTableCache = ArrayPool<int>.Shared.Rent(cacheSize * 2)
let gotoTableCache = ArrayPool<int>.Shared.Rent(cacheSize * 2)
// Clear the arrays since ArrayPool does not
Array.Clear(actionTableCache, 0, actionTableCache.Length)
Array.Clear(gotoTableCache, 0, gotoTableCache.Length)
use _cacheDisposal =
{ new IDisposable with
member _.Dispose() =
ArrayPool<int>.Shared.Return actionTableCache
ArrayPool<int>.Shared.Return gotoTableCache }
let actionTable = AssocTable(tables.actionTableElements, tables.actionTableRowOffsets, actionTableCache, cacheSize)
let gotoTable = AssocTable(tables.gotos, tables.sparseGotoTableRowOffsets, gotoTableCache, cacheSize)
let stateToProdIdxsTable = new IdxToIdxListTable(tables.stateToProdIdxsTableElements, tables.stateToProdIdxsTableRowOffsets)

let parseState =
Expand Down