Skip to content

Conversation

NinoFloris
Copy link
Member

@NinoFloris NinoFloris commented Dec 5, 2023

Column Seeking Rework

This PR reworks the split implementation we have for column seeking in NpgsqlDataReader.

Where previously we had two methods split by behavior; one for non buffered mode (sync only) and one for sequential mode (async/sync).

We now just have a sync and an async implementation, with the sync method having a tiny bit of additional validation for sequential behavior.

Fast paths should essentially be unaffected and we might even see a small speedup in TE non sequential scenarios due to streamlining column seeking but also PgReader.{Init,Commit} even more.

For the async implementation we're exploiting the fact that any rereading or rewinding necessarily means we already have the data. So we're able to fully delegate all that work to the sync implementation.

Similarly we're now always using the sync implementation if we know the row is buffered entirely.

Async Seeking Caveat

One optimization that I introduced in 8.0 that didn't make it over is when doing an *async sequential* seek (so mostly via IsDBNullAsync or GetFieldValueAsync). We used to try and seek up to the column that was buffered before switching to the async method, saving a small bit of time setting up the state machine and entering it.

In my opinion that complexity isn't worth carrying over. It was initially introduced because sequential seeking had no sync only method at all, impacting the super common sync methods like GetFieldValue. While the async column reading methods are rarely used. Even then the new implementation will still use the sync path when the entire row is buffered.

On the other hand *sync sequential* seeking now uses the same heavily optimized implementation as buffered mode does.

@NinoFloris NinoFloris force-pushed the rework-column-seeking branch from 845f822 to 067e640 Compare June 27, 2024 22:03
@NinoFloris NinoFloris force-pushed the rework-column-seeking branch 5 times, most recently from a1020df to ddf2369 Compare June 27, 2024 23:23
@NinoFloris NinoFloris modified the milestones: 8.0.4, 9.0.0 Jun 27, 2024
@NinoFloris NinoFloris force-pushed the rework-column-seeking branch from ddf2369 to 8a89705 Compare June 27, 2024 23:42
@NinoFloris NinoFloris merged commit 3592cee into main Jun 28, 2024
@NinoFloris NinoFloris deleted the rework-column-seeking branch June 28, 2024 14:37
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