FirebirdSql.Data.FirebirdClient icon indicating copy to clipboard operation
FirebirdSql.Data.FirebirdClient copied to clipboard

RFC: Reduce memory allocations [Do not merge]

Open fdcastel opened this issue 1 year ago • 5 comments

Initial work to reduce memory allocations.

Asking for guidance/opinions. Do not merge.

Before be56c23c7a623d7dfbe0132a2b6d479466d0ffc4

| Method | Count |             DataType |      Mean |     Error |   StdDev |       Gen0 |       Gen1 | Allocated |
|------- |------ |--------------------- |----------:|----------:|---------:|-----------:|-----------:|----------:|
|  Fetch | 10000 |               BIGINT |  56.14 ms |  0.714 ms | 0.039 ms |  1333.3333 |  1222.2222 |  10.86 MB |
|  Fetch | 10000 | BLOB SUB_TYPE BINARY | 182.51 ms | 56.430 ms | 3.093 ms | 24333.3333 | 12000.0000 | 196.11 MB |
|  Fetch | 10000 | BLOB (...) UTF8 [37] | 191.21 ms | 90.292 ms | 4.949 ms | 27000.0000 |  9000.0000 | 216.18 MB |
|  Fetch | 10000 | CHAR((...)CTETS [30] |  58.46 ms |  3.942 ms | 0.216 ms |  1625.0000 |   750.0000 |  13.31 MB |
|  Fetch | 10000 | CHAR((...) UTF8 [28] |  80.73 ms |  4.432 ms | 0.243 ms |  5666.6667 |  1333.3333 |  45.43 MB |

After 6a641d7079db56c489c73dd3e5158b4319cee242

| Method | Count |             DataType |      Mean |     Error |   StdDev |       Gen0 |       Gen1 | Allocated |
|------- |------ |--------------------- |----------:|----------:|---------:|-----------:|-----------:|----------:|
|  Fetch | 10000 |               BIGINT |  22.34 ms |  4.823 ms | 0.264 ms |   593.7500 |   562.5000 |   4.91 MB |
|  Fetch | 10000 | BLOB SUB_TYPE BINARY | 139.91 ms | 59.043 ms | 3.236 ms | 23750.0000 | 11750.0000 | 190.15 MB |
|  Fetch | 10000 | BLOB (...) UTF8 [37] | 141.46 ms | 57.728 ms | 3.164 ms | 26250.0000 | 12750.0000 | 210.22 MB |
|  Fetch | 10000 | CHAR((...)CTETS [30] |  24.28 ms |  5.843 ms | 0.320 ms |   937.5000 |   906.2500 |   7.66 MB |
|  Fetch | 10000 | CHAR((...) UTF8 [28] |  44.76 ms |  8.676 ms | 0.476 ms |  3666.6667 |  1166.6667 |  29.78 MB |

For now, integers (BIGINT row in the above benchmarks) shows the most significant improvement.

But there is also a lot of work yet to be done. Both in low level (Interop) as in strings management.

How to run

To run the above benchmarks, run (in Powershell/Windows):

.\download-firebird-binaries.ps1
.\benchmark.ps1 -Benchmark PerformanceBenchmark

The benchmark will use Firebird 5.0 Embedded. It should not conflict with any Firebird installed.

fdcastel avatar Jul 27 '23 19:07 fdcastel

@fdcastel I like the idea. We can take baby steps. Every little counts. Also, can you please resolve the conflicts. Thanks.

cincuranet avatar Oct 01 '23 15:10 cincuranet

Done! Please review.

P.S.: Remember that for these changes I had to remove net48, netstandard2.0 and net5.0 support.

fdcastel avatar Oct 01 '23 23:10 fdcastel

Sorry, @cincuranet -- Something in this commit is broken but I'm not able to debug it anymore for now.

I will review this in the next few days.

Meanwhile, the commits up to this are fine.

fdcastel avatar Oct 02 '23 02:10 fdcastel

I will review this in the next few days.

Fixed.

fdcastel avatar Oct 03 '23 02:10 fdcastel

@cincuranet any comments / considerations?

fdcastel avatar Oct 23 '23 13:10 fdcastel