Skip to content

Commit 2f9f274

Browse files
committed
Changed: Fixed large buffer rent caused by the default implementation of Stream.Read(Span<byte>)
Removed: qodana.yml Signed-off-by: JOSE FUXA <[email protected]>
1 parent 40efe71 commit 2f9f274

File tree

8 files changed

+52
-41
lines changed

8 files changed

+52
-41
lines changed

.editorconfig

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# EditorConfig is awesome:
2-
http://EditorConfig.org
1+
# EditorConfig is awesome: http://EditorConfig.org
32

43
# top-most EditorConfig file
54
root = true
@@ -12,6 +11,8 @@ trim_trailing_whitespace = true
1211

1312
# C# files
1413
[*.cs]
14+
charset = utf-8
15+
1516
# New line preferences
1617
csharp_new_line_before_open_brace = none
1718
csharp_new_line_before_catch = false
@@ -21,6 +22,13 @@ csharp_new_line_before_members_in_anonymous_types = false
2122
csharp_new_line_before_members_in_object_initializers = false
2223
csharp_new_line_within_query_expression_clauses = true
2324

25+
# use file-scoped namespaces
26+
csharp_style_namespace_declarations = file_scoped
27+
dotnet_diagnostic.IDE0161.severity = error
28+
29+
# use ValueTasks correctly
30+
dotnet_diagnostic.CA2012.severity = error
31+
2432
# Indentation preferences
2533
csharp_indent_block_contents = true
2634
csharp_indent_braces = false

.github/workflows/qodana.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ on:
33
push:
44
tags:
55
- "v*"
6+
7+
permissions:
8+
contents: read
9+
packages: write
10+
611
jobs:
712
release:
813
runs-on: ubuntu-latest
@@ -19,10 +24,13 @@ jobs:
1924
id: get_version
2025
run: echo "version=${GITHUB_REF:11}" >> $GITHUB_OUTPUT
2126

27+
- name: Debug Version Output
28+
run: echo "Version: ${{ steps.get_version.outputs.version }}"
29+
2230
- name: Build, Pack and Publish
2331
run: |
2432
dotnet pack /p:Version=${{ steps.get_version.outputs.version }} -o artefacts -c Release src/EventStore.Plugins/EventStore.Plugins.csproj
25-
dotnet nuget push artefacts/EventStore.Plugins.${{ steps.get_version.outputs.version }}.nupkg -k ${{ secrets.nugetkey }} -s https://api.nuget.org/v3/index.json
33+
dotnet nuget push artefacts/EventStore.Plugins.${{ steps.get_version.outputs.version }}.nupkg -k ${{ secrets.GITHUB_TOKEN }} -s https://nuget.pkg.github.com/TrogonStack/index.json
2634
- name: Create Release
2735
id: create_release
2836
uses: actions/create-release@v1

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ipch/
2424
*.DotSettings
2525
*.DotSettings.user
2626
*.DotSettings.personal/Logs
27-
*.md
27+
2828
!CHANGELOG.md
2929
/Data
3030
/src/Public/v8/

EventStore.Plugins.sln

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1212
.editorconfig = .editorconfig
1313
.gitignore = .gitignore
1414
LICENSE.md = LICENSE.md
15-
NOTICE.md = NOTICE.md
1615
qodana.yaml = qodana.yaml
1716
README.md = README.md
1817
EndProjectSection

src/EventStore.Plugins/EventStore.Plugins.csproj

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<Nullable>enable</Nullable>
99
<InvariantGlobalization>true</InvariantGlobalization>
1010
</PropertyGroup>
11-
11+
1212
<PropertyGroup>
1313
<PackageId>EventStore.Plugins</PackageId>
1414
<Authors>Event Store Ltd</Authors>
@@ -21,19 +21,24 @@
2121
<Copyright>Copyright 2012-2024 Event Store Ltd</Copyright>
2222
<PackageTags>eventstore plugins</PackageTags>
2323
</PropertyGroup>
24-
24+
25+
<PropertyGroup>
26+
<RepositoryUrl>https://github.com/TrogonStack/TrogonEventStore.Plugins</RepositoryUrl>
27+
<RepositoryType>git</RepositoryType>
28+
</PropertyGroup>
29+
2530
<ItemGroup>
2631
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="7.6.0" />
2732
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="8.0.1" />
2833
<PackageReference Include="YamlDotNet" Version="15.1.4" />
2934
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
3035
<PackageReference Include="System.Reactive" Version="6.0.1" />
3136
</ItemGroup>
32-
37+
3338
<ItemGroup>
3439
<FrameworkReference Include="Microsoft.AspNetCore.App" />
3540
</ItemGroup>
36-
41+
3742
<ItemGroup>
3843
<None Include="..\..\LICENSE.md" Pack="true" PackagePath="\" />
3944
<None Include="..\..\ouro.png" Pack="true" PackagePath="\" />

src/EventStore.Plugins/Transforms/ChunkDataReadStream.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.IO;
1+
using System.Runtime.CompilerServices;
32

43
namespace EventStore.Plugins.Transforms;
54

@@ -10,12 +9,26 @@ public class ChunkDataReadStream(Stream chunkFileStream) : Stream {
109
public sealed override bool CanSeek => true;
1110
public sealed override bool CanWrite => false;
1211
public sealed override void Write(byte[] buffer, int offset, int count) => throw new InvalidOperationException();
12+
public override void Write(ReadOnlySpan<byte> buffer) => throw new InvalidOperationException();
13+
public sealed override void WriteByte(byte value) => throw new InvalidOperationException();
14+
1315
public sealed override void Flush() => throw new InvalidOperationException();
1416
public sealed override void SetLength(long value) => throw new InvalidOperationException();
1517
public override long Length => throw new NotSupportedException();
1618

17-
// reads must always return exactly `count` bytes as we never read past the (flushed) writer checkpoint
18-
public override int Read(byte[] buffer, int offset, int count) => ChunkFileStream.Read(buffer, offset, count);
19+
public sealed override int Read(byte[] buffer, int offset, int count) {
20+
ValidateBufferArguments(buffer, offset, count);
21+
22+
return Read(buffer.AsSpan(offset, count));
23+
}
24+
25+
// reads must always return exactly `Span<byte>.Length` bytes as we never read past the (flushed) writer checkpoint
26+
public override int Read(Span<byte> buffer) => ChunkFileStream.Read(buffer);
27+
28+
public sealed override int ReadByte() {
29+
Unsafe.SkipInit(out byte value);
30+
return Read(new(ref value)) is 1 ? value : -1;
31+
}
1932

2033
// seeks need to support only `SeekOrigin.Begin`
2134
public override long Seek(long offset, SeekOrigin origin) {

src/EventStore.Plugins/Transforms/ChunkDataWriteStream.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ public class ChunkDataWriteStream(Stream chunkFileStream, HashAlgorithm checksum
1212
public sealed override bool CanSeek => false;
1313
public sealed override bool CanWrite => true;
1414
public sealed override int Read(byte[] buffer, int offset, int count) => throw new InvalidOperationException();
15+
public sealed override int Read(Span<byte> buffer) => throw new InvalidOperationException();
16+
public sealed override int ReadByte() => throw new InvalidOperationException();
17+
1518
public sealed override long Seek(long offset, SeekOrigin origin) => throw new InvalidOperationException();
1619

1720
public override void Write(byte[] buffer, int offset, int count) {
@@ -22,6 +25,7 @@ public override void Write(byte[] buffer, int offset, int count) {
2225
public override void Flush() => ChunkFileStream.Flush();
2326
public override void SetLength(long value) => ChunkFileStream.SetLength(value);
2427
public override long Length => ChunkFileStream.Length;
28+
2529
public override long Position {
2630
get => ChunkFileStream.Position;
2731
set {
@@ -31,7 +35,8 @@ public override long Position {
3135
ReadAndChecksum(value);
3236

3337
if (ChunkFileStream.Position != value)
34-
throw new Exception($"Writer's position ({ChunkFileStream.Position:N0}) is not at the expected position ({value:N0})");
38+
throw new Exception(
39+
$"Writer's position ({ChunkFileStream.Position:N0}) is not at the expected position ({value:N0})");
3540
}
3641
}
3742

0 commit comments

Comments
 (0)