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

Performance: Tasks / Struct #337

Merged
merged 14 commits into from
Sep 2, 2022
Prev Previous commit
Next Next commit
FsCodec rc6
  • Loading branch information
bartelink committed Sep 2, 2022
commit e347716227da09942960cb3b113eb730bf90b041
4 changes: 2 additions & 2 deletions samples/Store/Domain/Domain.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
<ItemGroup>
<PackageReference Include="FSharp.Core" Version="6.0.0" />

<PackageReference Include="FsCodec.NewtonsoftJson" Version="3.0.0-rc.5" />
<PackageReference Include="FsCodec.SystemTextJson" Version="3.0.0-rc.5" />
<PackageReference Include="FsCodec.NewtonsoftJson" Version="3.0.0-rc.6" />
<PackageReference Include="FsCodec.SystemTextJson" Version="3.0.0-rc.6" />

<ProjectReference Include="..\..\..\src\Equinox\Equinox.fsproj" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions samples/Tutorial/Tutorial.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="FsCodec.NewtonsoftJson" Version="3.0.0-rc.5" />
<PackageReference Include="FsCodec.SystemTextJson" Version="3.0.0-rc.5" />
<PackageReference Include="FsCodec.NewtonsoftJson" Version="3.0.0-rc.6" />
<PackageReference Include="FsCodec.SystemTextJson" Version="3.0.0-rc.6" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
<PackageReference Include="Serilog.Sinks.Seq" Version="5.1.1" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion samples/Tutorial/Upload.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module CompanyId =
let toString (value : CompanyId) : string = %value

let [<Literal>] Category = "Upload"
let streamName (companyId, purchaseOrderId) = struct (Category, FsCodec.StreamName.createAggregateId [PurchaseOrderId.toString purchaseOrderId; CompanyId.toString companyId])
let streamName (companyId, purchaseOrderId) = struct (Category, FsCodec.StreamName.createStreamId [PurchaseOrderId.toString purchaseOrderId; CompanyId.toString companyId])

type UploadId = string<uploadId>
and [<Measure>] uploadId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ type LogSink(customTags: seq<string * string>) =
payloadCounters (facet, op, outcome) (db, con, cat, float count, if bytes = -1 then None else Some (float bytes))

let (|CatSRu|) ({ interval = i; ru = ru } : Measurement as m) =
let struct (cat, _id) = FsCodec.StreamName.splitCategoryAndId (FSharp.UMX.UMX.tag m.stream)
let struct (cat, _id) = FsCodec.StreamName.splitCategoryAndStreamId (FSharp.UMX.UMX.tag m.stream)
struct (m.database, m.container, cat, i.Elapsed, ru)
let observeRes (_rut, facet, _op as stat) (CatSRu (db, con, cat, s, ru)) =
roundtripHistogram stat (db, con, cat, s, ru)
Expand Down
11 changes: 6 additions & 5 deletions src/Equinox.CosmosStore/CosmosStore.fs
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,9 @@ module Log =
{ mutable rux100 : int64; mutable count : int64; mutable ms : int64 }
static member Create() = { rux100 = 0L; count = 0L; ms = 0L }
member x.Ingest(ru, ms) =
System.Threading.Interlocked.Increment(&x.count) |> ignore
System.Threading.Interlocked.Add(&x.rux100, int64 (ru*100.)) |> ignore
System.Threading.Interlocked.Add(&x.ms, ms) |> ignore
Interlocked.Increment(&x.count) |> ignore
Interlocked.Add(&x.rux100, int64 (ru*100.)) |> ignore
Interlocked.Add(&x.ms, ms) |> ignore
let inline private (|RcMs|) ({ interval = i; ru = ru } : Measurement) =
ru, let e = i.Elapsed in int64 e.TotalMilliseconds
type LogSink() =
Expand Down Expand Up @@ -1162,7 +1162,6 @@ namespace Equinox.CosmosStore

open Equinox.Core
open Equinox.CosmosStore.Core
open FsCodec
open Microsoft.Azure.Cosmos
open System
open System.Threading.Tasks
Expand Down Expand Up @@ -1301,7 +1300,9 @@ type CosmosStoreClient
[<O; D null>] ?archiveDatabaseId,
// Container Name to use for locating missing events. Default: use <c>containerId</c>
[<O; D null>] ?archiveContainerId) =
let genStreamName (categoryName, streamId) = if categoryName = null then streamId else StreamName.createRaw (categoryName, streamId)
let genStreamName (categoryName, streamId) =
if categoryName = null then streamId
else FsCodec.StreamName.Internal.ofCategoryAndStreamId (categoryName, streamId)
let catAndStreamToDatabaseContainerStream (categoryName, streamId) = databaseId, containerId, genStreamName (categoryName, streamId)
let primaryContainer (d, c) = (client : CosmosClient).GetDatabase(d).GetContainer(c)
let fallbackContainer =
Expand Down
2 changes: 1 addition & 1 deletion src/Equinox.CosmosStore/Equinox.CosmosStore.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<PackageReference Include="FSharp.Core" Version="6.0.0" />

<PackageReference Include="FsCodec" Version="3.0.0-rc.5" />
<PackageReference Include="FsCodec" Version="3.0.0-rc.6" />
<PackageReference Include="FSharp.Control.AsyncSeq" Version="2.0.23" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.27.0" />
<PackageReference Include="System.Text.Json" Version="6.0.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ type LogSink(customTags: seq<string * string>) =
payloadCounters (facet, op, outcome) (table, cat, float count, if bytes = -1 then None else Some (float bytes))

let (|CatSRu|) ({ interval = i; ru = ru } : Measurement as m) =
let struct (cat, _id) = FsCodec.StreamName.splitCategoryAndId (FSharp.UMX.UMX.tag m.stream)
let struct (cat, _id) = FsCodec.StreamName.splitCategoryAndStreamId (FSharp.UMX.UMX.tag m.stream)
struct (m.table, cat, i.Elapsed, ru)
let observeRes (_rut, facet, _op as stat) (CatSRu (table, cat, s, ru)) =
roundtripHistogram stat (table, cat, s, ru)
Expand Down
4 changes: 3 additions & 1 deletion src/Equinox.DynamoStore/DynamoStore.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,9 @@ type DynamoStoreClient
[<O; D null>] ?archiveTableName,
// Client to use for archive store. Default: (if <c>archiveTableName</c> specified) use same <c>archiveTableName</c> but via <c>client</c>.
[<O; D null>] ?archiveClient : Amazon.DynamoDBv2.IAmazonDynamoDB) =
let genStreamName (categoryName, streamId) = if categoryName = null then streamId else FsCodec.StreamName.createRaw (categoryName, streamId)
let genStreamName (categoryName, streamId) =
if categoryName = null then streamId else
FsCodec.StreamName.Internal.ofCategoryAndStreamId (categoryName, streamId)
let catAndStreamToTableStream (categoryName, streamId) = tableName, genStreamName (categoryName, streamId)
let primaryContainer t = Container.Create(client, t)
let fallbackContainer =
Expand Down
2 changes: 1 addition & 1 deletion src/Equinox.DynamoStore/Equinox.DynamoStore.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<PackageReference Include="FSharp.Core" Version="6.0.0" />

<PackageReference Include="FsCodec" Version="3.0.0-rc.5" />
<PackageReference Include="FsCodec" Version="3.0.0-rc.6" />
<PackageReference Include="FSharp.AWS.DynamoDB" Version="0.11.1-beta" />
<PackageReference Include="FSharp.Control.AsyncSeq" Version="2.0.23" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Equinox.EventStore/Equinox.EventStore.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<PackageReference Include="FSharp.Core" Version="6.0.0" />

<PackageReference Include="EventStore.Client" Version="22.0.0-preview" />
<PackageReference Include="FsCodec" Version="3.0.0-rc.5" />
<PackageReference Include="FsCodec" Version="3.0.0-rc.6" />
<PackageReference Include="FSharp.Control.AsyncSeq" Version="2.0.23" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Equinox.EventStore/EventStore.fs
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ type EventStoreCategory<'event, 'state, 'context>(resolveInner, empty) =
Caching.applyCacheUpdatesWithFixedTimeSpan cache null period folder Token.supersedes
| Some (CachingStrategy.SlidingWindowPrefixed (cache, window, prefix)) ->
Caching.applyCacheUpdatesWithSlidingExpiration cache prefix window folder Token.supersedes
let resolveInner streamIds = struct (category, FsCodec.StreamName.createRaw streamIds, ValueNone)
let resolveInner streamIds = struct (category, FsCodec.StreamName.Internal.ofCategoryAndStreamId streamIds, ValueNone)
let empty = struct (context.TokenEmpty, initial)
EventStoreCategory(resolveInner, empty)

Expand Down
2 changes: 1 addition & 1 deletion src/Equinox.EventStoreDb/Equinox.EventStoreDb.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<PackageReference Include="FSharp.Core" Version="6.0.0" />

<PackageReference Include="EventStore.Client.Grpc.Streams" Version="22.0.0" />
<PackageReference Include="FsCodec" Version="3.0.0-rc.5" />
<PackageReference Include="FsCodec" Version="3.0.0-rc.6" />
<PackageReference Include="FSharp.Control.AsyncSeq" Version="2.0.23" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Equinox.EventStoreDb/EventStoreDb.fs
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ type EventStoreCategory<'event, 'state, 'context>(resolveInner, empty) =
Caching.applyCacheUpdatesWithFixedTimeSpan cache null period folder Token.supersedes
| Some (CachingStrategy.SlidingWindowPrefixed (cache, window, prefix)) ->
Caching.applyCacheUpdatesWithSlidingExpiration cache prefix window folder Token.supersedes
let resolveInner streamIds = struct (category, FsCodec.StreamName.createRaw streamIds, ValueNone)
let resolveInner streamIds = struct (category, FsCodec.StreamName.Internal.ofCategoryAndStreamId streamIds, ValueNone)
let empty = struct (context.TokenEmpty, initial)
EventStoreCategory(resolveInner, empty)

Expand Down
2 changes: 1 addition & 1 deletion src/Equinox.MemoryStore/Equinox.MemoryStore.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<PackageReference Include="FSharp.Core" Version="6.0.0" />

<PackageReference Include="FsCodec" Version="3.0.0-rc.5" />
<PackageReference Include="FsCodec" Version="3.0.0-rc.6" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Equinox.MemoryStore/MemoryStore.fs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ type MemoryStoreCategory<'event, 'state, 'Format, 'context>(resolveInner, empty)
inherit Equinox.Category<'event, 'state, 'context>(resolveInner, empty)
new (store : VolatileStore<'Format>, codec : FsCodec.IEventCodec<'event, 'Format, 'context>, fold, initial) =
let impl = Category<'event, 'state, 'context, 'Format>(store, codec, fold, initial)
let resolveInner streamIds = struct (impl :> ICategory<_, _, _>, FsCodec.StreamName.createRaw streamIds, ValueNone)
let resolveInner streamIds = struct (impl :> ICategory<_, _, _>, FsCodec.StreamName.Internal.ofCategoryAndStreamId streamIds, ValueNone)
let empty = struct (Token.ofEmpty, initial)
MemoryStoreCategory(resolveInner, empty)
2 changes: 1 addition & 1 deletion src/Equinox.SqlStreamStore/Equinox.SqlStreamStore.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<PackageReference Include="FSharp.Core" Version="6.0.0" />

<PackageReference Include="FsCodec" Version="3.0.0-rc.5" />
<PackageReference Include="FsCodec" Version="3.0.0-rc.6" />
<PackageReference Include="FSharp.Control.AsyncSeq" Version="2.0.23" />
<PackageReference Include="SqlStreamStore" Version="1.2.0-beta.8" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Equinox.SqlStreamStore/SqlStreamStore.fs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ type SqlStreamStoreCategory<'event, 'state, 'context>(resolveInner, empty) =
Caching.applyCacheUpdatesWithFixedTimeSpan cache null period folder Token.supersedes
| Some (CachingStrategy.SlidingWindowPrefixed (cache, window, prefix)) ->
Caching.applyCacheUpdatesWithSlidingExpiration cache prefix window folder Token.supersedes
let resolveInner streamIds = struct (category, FsCodec.StreamName.createRaw streamIds, ValueNone)
let resolveInner streamIds = struct (category, FsCodec.StreamName.Internal.ofCategoryAndStreamId streamIds, ValueNone)
let empty = struct (context.TokenEmpty, initial)
SqlStreamStoreCategory(resolveInner, empty)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ type Tests(testOutputHelper) =
// Needs to share the same context (with inner CosmosClient) for the session token to be threaded through
// If we run on an independent context, we won't see (and hence prune) the full set of events
let ctx = Core.EventsContext(context, log)
let streamName = ContactPreferences.streamName id |> FsCodec.StreamName.createRaw
let streamName = ContactPreferences.streamName id |> FsCodec.StreamName.Internal.ofCategoryAndStreamId

// Prune all the events
let! deleted, deferred, trimmedPos = Core.Events.pruneUntil ctx streamName 14L
Expand Down Expand Up @@ -410,7 +410,7 @@ type Tests(testOutputHelper) =
(* Verify pruning does not affect snapshots, though Tip is re-read in this scenario due to lack of caching *)

let ctx = Core.EventsContext(context, log)
let streamName = Cart.streamName cartId |> FsCodec.StreamName.createRaw
let streamName = Cart.streamName cartId |> FsCodec.StreamName.Internal.ofCategoryAndStreamId
// Prune all the events
let! deleted, deferred, trimmedPos = Core.Events.pruneUntil ctx streamName 11L
test <@ deleted = 12 && deferred = 0 && trimmedPos = 12L @>
Expand Down Expand Up @@ -471,7 +471,7 @@ type Tests(testOutputHelper) =
(* Verify pruning does not affect snapshots, and does not touch the Tip *)

let ctx = Core.EventsContext(context, log)
let streamName = Cart.streamName cartId |> FsCodec.StreamName.createRaw
let streamName = Cart.streamName cartId |> FsCodec.StreamName.Internal.ofCategoryAndStreamId
// Prune all the events
let! deleted, deferred, trimmedPos = Core.Events.pruneUntil ctx streamName 12L
test <@ deleted = 13 && deferred = 0 && trimmedPos = 13L @>
Expand Down
2 changes: 1 addition & 1 deletion tools/Equinox.Tool/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ module Dump =
with e -> log.Warning(e, "UTF-8 Parse failure - use --Blobs option to inhibit"); reraise()
let readStream (streamName : FsCodec.StreamName) = async {
let resolve = store.Category(idCodec, fold, initial, isOriginAndSnapshot) |> Equinox.Decider.resolve storeLog
let decider = resolve (FsCodec.StreamName.splitCategoryAndId streamName)
let decider = resolve (FsCodec.StreamName.splitCategoryAndStreamId streamName)
let! streamBytes, events = decider.QueryEx(fun c -> c.StreamEventBytes, c.State)
let mutable prevTs = None
for x in events |> Seq.filter (fun e -> (e.IsUnfold && doU) || (not e.IsUnfold && doE)) do
Expand Down