Skip to content

Conversation

@vonzshik
Copy link
Contributor

@vonzshik vonzshik commented Mar 4, 2023

Closes #3898
Part of #4965

This change saves us 8kb on linux (and around 20kb on windows).

@vonzshik vonzshik requested a review from roji as a code owner March 4, 2023 06:45
void AddUserMappingResolver(IUserTypeMapping userMapping)
{
RemoveUserMappingResolver(userMapping.PgTypeName);
var factory = new UserMappedTypeHandlerResolverFactory(userMapping);
Copy link
Member

Choose a reason for hiding this comment

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

Originally I thought of the resolvers list as always being quite small, e.g. how many plugins could there possibly be.. I'm not sure if we have places where perf would be problematic if this list starts growing; IIRC we should only actually access the resolvers for NpgsqlDbType/Type that we haven't seen before (we cache). Maybe on connection startup (when the cache is empty) this could in theory become problematic, if the user has e.g. 200 enums/composites or something.

To be on the safe side, we could have a single resolver handle them all; though if you're convinced this doesn't matter I'm OK with it.

Copy link
Contributor Author

@vonzshik vonzshik Mar 10, 2023

Choose a reason for hiding this comment

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

Maybe on connection startup (when the cache is empty) this could in theory become problematic, if the user has e.g. 200 enums/composites or something.

You do have a point here. A few of my thoughts below:

  1. With 200+ enums/composites a cold start will be slow no matter what we do (as it implies a big codebase).
  2. One way to go around this is to implement resolver sorting. Since enums/composites don't interfere with BuiltInResolver (and the same thing can be said about all of the resolvers we implement in Implement NpgsqlDataSource #4495) we can put BuiltInResolver first and enums/composites last (+ resolvers from Implement NpgsqlDataSource #4495).
  3. While we do cache the results of the resolvers, there is an exception to that rule: resolving by value. Because of DateTime's kind we have to return either timestamp or timestamptz.

In light of the above I propose:

  1. We do implement a single resolver for custom types.
  2. We consider sorting resolvers (putting BuiltInResolver first, most of out internal resolvers after, and anything a user adds before BuiltInResolver).

What do you say?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We do implement a single resolver for custom types.

Though that's probably going to complicate things for the global type mapper...

Copy link
Member

Choose a reason for hiding this comment

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

@NinoFloris what do you think of the above? We've discussed simplying our type handler concepts by bringing ideas across from Slon; if we do that, it may not be worth worrying too much about the current situation...

Copy link
Member

Choose a reason for hiding this comment

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

Right, Slon's model also relies on resolvers for this work so in that respect nothing changes. If there are a huge number of (user) resolvers to check before ending up at the builtin set it would equally slow things down until the cache is properly filled.

I would probably have something like the following order:

  • Builtin
  • User mappings (just one resolver)
  • (Additive) plugins (however many resolvers as there are plugins)

In Slon the only time you need another resolver to be first is for overriding the given converter for some clr type or overriding info (default clr type for a pg type, text writing preferred etc).

This comment was marked as resolved.

This comment was marked as resolved.

@NinoFloris NinoFloris mentioned this pull request Aug 15, 2023
8 tasks
@NinoFloris NinoFloris added this to the 8.0.0 milestone Sep 25, 2023
@Brar Brar removed this from the 8.0.0 milestone Nov 21, 2023
@NinoFloris NinoFloris deleted the 3898-rewrite-user-type-mapping branch March 27, 2024 17:41
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.

Remove Bind during AddMapping

4 participants