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

Don't look up the type oid for types that never use it #168

Merged

Conversation

JLockerman
Copy link
Contributor

Getting function argument type oids can be surprisingly expensive; one Promscale benchmark measures it as taking over 10% of runtime (@cevian should have more info). Fortunately, most types do not actually make use of this information, and the getarg_type() call can be optimized out if this fact is known. This commit adds an opt-in method for declaring that a type does not make use of the typeoid in from_datum(), and updates pg_getarg() to make use of this information.

This commit makes the following changes:

  1. It adds a const boolean to FromDatum called NEEDS_TYPID. This boolean is defaulted to true. Types that never use the typeoid parameter to from_datum() can override this to false.
  2. pg_getarg() updated to look at T::NEEDS_TYPID before calling get_getarg_type(). If T::NEEDS_TYPID == true it calls get_getarg_type() like it currently does for all types; if it is false it instead passes InvalidOid as the (unused) typeoid argument to from_datum().
  3. It edits a number of built in types to make use of this optimization.

Since this feature is both opt-in and backwards compatible, it should not break any downstream users.

Getting function argument type oids can be surprisingly expensive; one
Promscale benchmark measures it as taking over 10% of runtime.
Fortunately, most types do not actually make use of this information,
and the `getarg_type()` call can be optimized out if this fact is
known. This commit adds an opt-in method for declaring that a type does
not make use of the `typeoid` in `from_datum()`, and updates
`pg_getarg()` to make use of this information.

This commit makes the following changes:
 1. It adds a `const` boolean to `FromDatum` called `NEEDS_TYPID`. This
    boolean is defaulted to `true`. Types that never use the `typeoid`
    parameter to `from_datum()` can override this to `false`.
 2. `pg_getarg()` updated to look at `T::NEEDS_TYPID` before calling
    `get_getarg_type()`. If `T::NEEDS_TYPID == true` it calls
    `get_getarg_type()` like it currently does for all types; if it is
    `false` it instead passes `InvalidOid` as the (unused) `typeoid`
    argument to `from_datum()`.
 3. It edits a number of built in types to make use of this
    optimization.

Since this feature is both opt-in and backwards compatible, it should
not break any downstream users.
Copy link
Contributor

@Hoverbear Hoverbear left a comment

Choose a reason for hiding this comment

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

Thanks for this! :)

@Hoverbear Hoverbear merged commit 13d784d into pgcentralfoundation:develop Sep 3, 2021
@Hoverbear Hoverbear added this to the 0.2.0 milestone Sep 24, 2021
This was referenced Sep 24, 2021
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.

None yet

2 participants