Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up connection-specific mapping changes #2263

Closed
roji opened this issue Dec 13, 2018 · 3 comments · Fixed by #3824
Closed

Speed up connection-specific mapping changes #2263

roji opened this issue Dec 13, 2018 · 3 comments · Fixed by #3824
Assignees
Milestone

Comments

@roji
Copy link
Member

roji commented Dec 13, 2018

Npgsql allows users to change type mappings, either by plugins or manually. Changes can be done at two levels:

  • The global type mapper (static NpgsqlConnection.GlobalTypeMapper). This holds for all connections
  • The connection-specific type mapper (non-static NpgsqlConnection.TypeMapper).

Changes to the connection-specific type mapper need to be restricted to the lifetime of the connection. That is, when a connection is returned to the pool, all changes must be reset, otherwise they will leak once the physical connection is returned again.

The current method for handling this checking whether any changes were done, and if so, disposing the entire type mapper and rebuilding mappings from scratch. This is a pretty heavy process that makes connection-based type mapping not very suitable for high-perf scenarios.

Instead, we could setup a sort of "undo list", tracking which mappings were changed and what needs to be done to reset them back.

@roji
Copy link
Member Author

roji commented Jun 12, 2019

Another idea: if a global type mapping exists, and then the same mapping is done on a specific connection, simply ignore that entirely. See npgsql/efcore.pg#895 (comment).

@roji
Copy link
Member Author

roji commented Sep 17, 2020

Less important now that the NodaTime plugin supports the BCL types (thanks @davidroth)

@roji roji modified the milestones: 5.0, Backlog Sep 17, 2020
@roji
Copy link
Member Author

roji commented Jun 9, 2021

Note: this was considerably improved by implementing lazy type handler binding (#3816). Resetting the type mapper now simply involves reverting to the global type mappings (very light), and clearing all existing type handler bindings. Since type handlers are now lazy, we no longer need to eagerly rebind everything.

While theoretically we could improve things further (i.e. really track what changes were done on the connector type mapper and only revert those), there seems like there's really little value there at this point.

@roji roji modified the milestones: Backlog, 6.0.0 Jun 9, 2021
roji added a commit that referenced this issue Jun 9, 2021
roji added a commit that referenced this issue Jun 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant