You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Writing a decimal as numeric allocates a short[9] per value #6728
For a decimal, bits.Length is 3, so the bound is (3 * 10 + 3) / 4 + 1 = 9. That is more than 8, so every non-null value allocates a short[9] (48 B), and the stack buffer is never used. The same converter is used for byte, short, int, long, float and double mapped to numeric, and for numeric ranges and multiranges.
A decimal never needs more than 8 numeric digits. The 9th slot is the builder's generic headroom, so the buffer is one short too small for the check.
TypeHandlers.Numeric.Write on main (b35800b), BenchmarkDotNet ShortRun, .NET 10.0.14: all 15 benchmark values allocate 48 B per op.
This is unrelated to #6509, which is a read-side bug in PgNumeric.Builder.ToDecimal.
Further technical details
Npgsql version: main (11.0.0-preview.1, b35800b); also present in 10.0.3
PostgreSQL version: any (client side)
Operating system: any
Activity
Avoid allocating a digits array when writing decimal as numeric
Avoid allocating a digits array when writing decimal as numeric