Skip to content

Read write streamlining - #6317

Closed
NinoFloris wants to merge 33 commits into
npgsql:mainfrom
NinoFloris:read-write-streamlining
Closed

NinoFloris wants to merge 33 commits into
npgsql:mainfrom
NinoFloris:read-write-streamlining

Conversation

@NinoFloris

Copy link
Copy Markdown
Member

Subsequent changes based on #6316

@NinoFloris
NinoFloris force-pushed the read-write-streamlining branch from 33734b1 to de4ce7b Compare November 16, 2025 23:51
@NinoFloris
NinoFloris force-pushed the read-write-streamlining branch from de4ce7b to 400870a Compare February 21, 2026 08:48
@NinoFloris
NinoFloris force-pushed the read-write-streamlining branch from 400870a to 7967f91 Compare April 12, 2026 13:05
@NinoFloris
NinoFloris marked this pull request as ready for review April 12, 2026 13:55
Copilot AI review requested due to automatic review settings April 12, 2026 13:55
@NinoFloris

Copy link
Copy Markdown
Member Author

Not quite ready for review, but still the only way to get copilot reviews.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR continues the “read/write streamlining” refactor (following #6316) by pushing more read/write call sites to use concrete type info plus explicit binding/context structs, reducing duplicated “provider vs concrete” branching and centralizing conversion decisions.

Changes:

  • Replace per-column converter caching with ReadConversionContext (concrete type info + PgFieldBinding) across readers/exporters/replication.
  • Rework parameter binding/writing around PgConcreteTypeInfo, PgValueBinding, and nested object DBNull handling.
  • Introduce new internal helpers/structs (Field.CreateUnspecified, NestedObjectDbNullHandling, ThrowHelper.ThrowUnreachableException, etc.) to support the new flow.

Reviewed changes

Copilot reviewed 37 out of 37 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
test/Npgsql.Tests/ReaderTests.cs Updates reader init/start APIs to new binding/context signatures.
test/Npgsql.Tests/NpgsqlParameterTests.cs Adjusts parameter resolution assertions to new resolution info shape.
test/Npgsql.Benchmarks/TypeHandlers/TypeHandlerBenchmarks.cs Migrates benchmark read/write setup to PgValueBinding/PgFieldBinding and generic converters.
test/Npgsql.Benchmarks/GetFieldValue.cs Minor benchmark config/comment tweak.
src/Npgsql/Util/TypeExtensions.cs Adds subtype-relationship helper used by new requested-type logic.
src/Npgsql/TypeMapping/GlobalTypeMapper.cs Simplifies datatype name inference via MakeConcreteForValueAsObject.
src/Npgsql/ThrowHelper.cs Adds ThrowUnreachableException(string? message = null) overload.
src/Npgsql/Replication/PgOutput/ReplicationValue.cs Switches replication value reads to ReadConversionContext and ReadFieldValue* helpers.
src/Npgsql/NpgsqlParameter`.cs Reworks generic parameter typed-value binding/writing to new concrete/binding APIs.
src/Npgsql/NpgsqlParameter.cs Major refactor of type resolution, binding, stream truncation handling, and writing pipeline.
src/Npgsql/NpgsqlNestedDataReader.cs Moves nested reader conversion caching to ReadConversionContext.
src/Npgsql/NpgsqlDataReader.cs Migrates main reader caching and read paths to ReadConversionContext.
src/Npgsql/NpgsqlBinaryImporter.cs Updates resolution rollback logic to track concrete type info instead of converter/typeid trio.
src/Npgsql/NpgsqlBinaryExporter.cs Refactors read paths to ReadConversionContext and field binding.
src/Npgsql/Internal/TypeInfoMapping.cs Adjusts composed type info creation to use requestedType model (replacing unboxed/boxing logic).
src/Npgsql/Internal/TypeInfoCache.cs Updates compatibility validation around IsStronglyTyped.
src/Npgsql/Internal/ResolverFactories/UnmappedTypeInfoResolverFactory.cs Updates to ToStronglyTyped and requestedType plumbing.
src/Npgsql/Internal/ResolverFactories/NetworkTypeInfoResolverFactory.cs Updates PgConcreteTypeInfo construction to use requestedType.
src/Npgsql/Internal/ResolverFactories/AdoTypeInfoResolverFactory.cs Updates mappings to new requestedType semantics for text/stream/jsonb/bytea.
src/Npgsql/Internal/Postgres/Field.cs Adds Field.CreateUnspecified helper for new binding paths.
src/Npgsql/Internal/PgWriter.cs Introduces StartWrite/EndWrite and separates commit/reset accounting.
src/Npgsql/Internal/PgTypeInfo.cs Large refactor: new concrete/provider responsibilities, plus PgFieldBinding/PgValueBinding and read/write helpers.
src/Npgsql/Internal/PgSerializerOptions.cs Updates unspecified DBNull type info to new ctor (requestedType).
src/Npgsql/Internal/PgReader.cs Changes Init parameter order and StartRead* to accept PgFieldBinding.
src/Npgsql/Internal/PgConverter.cs Refines DBNull predicate model and adds nested-object DBNull handling configuration.
src/Npgsql/Internal/PgConcreteTypeInfoProvider.cs Extends ProviderValueContext with NestedObjectDbNullHandling.
src/Npgsql/Internal/PgComposingTypeInfoProvider.cs Updates composing providers for new requested-type propagation.
src/Npgsql/Internal/Converters/RecordConverter.cs Uses MakeConcreteForField + BindField in nested reads.
src/Npgsql/Internal/Converters/PolymorphicArrayTypeInfoProvider.cs Updates to new provider APIs (GetDefault/GetForField).
src/Npgsql/Internal/Converters/ObjectConverter.cs Switches to new concrete/buffer requirements APIs.
src/Npgsql/Internal/Converters/NullableConverter.cs Adapts composing provider API (CreateConverter(..., out requestedType)).
src/Npgsql/Internal/Converters/CastingConverter.cs Makes casting converter public and updates type compatibility checks.
src/Npgsql/Internal/Converters/ArrayConverterCore.cs Threads NestedObjectDbNullHandling through array sizing/writing state.
src/Npgsql/Internal/Converters/ArrayConverter.cs Uses concrete type info sizing for nested object elements and updated provider APIs.
src/Npgsql/Internal/Composites/Metadata/CompositeFieldInfo.cs Updates composite field read/write info selection to new concrete/binding APIs.
src/Npgsql/Internal/BufferRequirements.cs Removes negative-size guard in GetMinimumBufferByteCount.
src/Npgsql/BackendMessages/RowDescriptionMessage.cs Replaces ColumnInfo caching with ReadConversionContext and exposes GetConversionContext.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Npgsql/Util/TypeExtensions.cs Resolved
Comment thread src/Npgsql/Internal/PgTypeInfo.cs Resolved
Comment thread src/Npgsql/Internal/PgWriter.cs Resolved
Comment thread src/Npgsql/NpgsqlParameter.cs Resolved
Comment thread src/Npgsql/NpgsqlNestedDataReader.cs Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 37 out of 37 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Npgsql/NpgsqlParameter.cs Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 38 out of 38 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Npgsql/NpgsqlParameter.cs Resolved
Comment thread src/Npgsql/NpgsqlBinaryExporter.cs Resolved
Comment thread src/Npgsql/NpgsqlNestedDataReader.cs Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 38 out of 38 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Npgsql/Internal/PgTypeInfo.cs Resolved
Comment thread src/Npgsql/Internal/PgTypeInfo.cs Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 38 out of 38 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Npgsql/NpgsqlNestedDataReader.cs Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 38 out of 38 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 38 out of 38 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

test/Npgsql.Benchmarks/TypeHandlers/TypeHandlerBenchmarks.cs:54

  • In the constructor, handler is already typed as PgConverter<T>; the explicit cast to (PgConverter<T>)handler is redundant and only exists to enable the null-coalescing throw. Consider simplifying to handler ?? throw ... (and optionally marking the parameter as nullable if you really want to allow null) to reduce noise in this benchmark base class.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Npgsql/Util/TypeExtensions.cs Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 38 out of 38 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 41 out of 41 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Npgsql/Internal/PgWriter.cs Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 41 out of 41 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 41 out of 41 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@NinoFloris

NinoFloris commented May 19, 2026 •

Copy link
Copy Markdown
Member Author

Closing. The original goals of this PR, and more, have been implemented across a number of separate PRs due to the volume and diversity of changes.

@NinoFloris NinoFloris closed this May 19, 2026
@NinoFloris
NinoFloris deleted the read-write-streamlining branch May 19, 2026 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants