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

IL: optimize attribute cluster reading #13821

Merged
merged 8 commits into from
Sep 23, 2022
Merged
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 38 additions & 13 deletions src/Compiler/AbstractIL/ilread.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1220,9 +1220,12 @@ type ISeekReadIndexedRowReader<'RowT, 'KeyT, 'T when 'RowT: struct> =
abstract CompareKey: 'KeyT -> int
abstract ConvertRow: byref<'RowT> -> 'T

let seekReadIndexedRowsByInterface numRows binaryChop (reader: ISeekReadIndexedRowReader<'RowT, _, _>) =
let seekReadIndexedRowsRange numRows binaryChop (reader: ISeekReadIndexedRowReader<'RowT, _, _>) =
let mutable row = Unchecked.defaultof<'RowT>

let mutable startRid = -1
let mutable endRid = -1

if binaryChop then
let mutable low = 0
let mutable high = numRows + 1
Expand All @@ -1241,12 +1244,12 @@ let seekReadIndexedRowsByInterface numRows binaryChop (reader: ISeekReadIndexedR
elif c < 0 then high <- mid
else fin <- true

let res = ImmutableArray.CreateBuilder()

if high - low > 1 then
// now read off rows, forward and backwards
let mid = (low + high) / 2

startRid <- mid

// read backwards
let mutable fin = false
let mutable curr = mid - 1
Expand All @@ -1258,14 +1261,12 @@ let seekReadIndexedRowsByInterface numRows binaryChop (reader: ISeekReadIndexedR
reader.GetRow(curr, &row)

if reader.CompareKey(reader.GetKey(&row)) = 0 then
res.Add(reader.ConvertRow(&row))
startRid <- curr
else
fin <- true

curr <- curr - 1

res.Reverse()

// read forward
let mutable fin = false
let mutable curr = mid
Expand All @@ -1277,23 +1278,47 @@ let seekReadIndexedRowsByInterface numRows binaryChop (reader: ISeekReadIndexedR
reader.GetRow(curr, &row)

if reader.CompareKey(reader.GetKey(&row)) = 0 then
res.Add(reader.ConvertRow(&row))
endRid <- curr
else
fin <- true

curr <- curr + 1

res.ToArray()
else
let res = ImmutableArray.CreateBuilder()
let mutable rid = 1

for i = 1 to numRows do
reader.GetRow(i, &row)
while rid <= numRows && startRid = -1 do
reader.GetRow(rid, &row)

if reader.CompareKey(reader.GetKey(&row)) = 0 then
res.Add(reader.ConvertRow(&row))
startRid <- rid
endRid <- rid

rid <- rid + 1

let mutable fin = false

while rid <= numRows && not fin do
reader.GetRow(rid, &row)

if reader.CompareKey(reader.GetKey(&row)) = 0 then
endRid <- rid
else
fin <- true

startRid, endRid

let seekReadIndexedRowsByInterface numRows binaryChop (reader: ISeekReadIndexedRowReader<'RowT, _, _>) =
let startRid, endRid = seekReadIndexedRowsRange numRows binaryChop reader

if startRid <= 0 || endRid < startRid then
[||]
else

res.ToArray()
Array.init (endRid - startRid + 1) (fun i ->
let mutable row = Unchecked.defaultof<'RowT>
reader.GetRow(startRid + i, &row)
reader.ConvertRow(&row))

[<Struct>]
type CustomAttributeRow =
Expand Down