Skip to content

Performance regression from marking c_PQnfields safe #70

Description

@ChickenProp

I had a benchmark slow down significantly when upgrading from 0.9.5.0 to 0.10.0.0. On profiling, the problem was that the ~2.3 million calls to nfields went from taking almost no time to taking ~1s.

c_PQnfields was marked safe in #48 because it's hard to know whether libpq functions are actually okay to be unsafe or not. In this case, looking at https://github.com/postgres/postgres/blame/50e6eb731d98ab6d0e625a0b87fb327b172bbebd/src/interfaces/libpq/fe-exec.c#L3489, the code is:

int
PQnfields(const PGresult *res)
{
	if (!res)
		return 0;
	return res->numAttributes;
}

I'm pretty sure that would be safe as-is; and it seems it hasn't been updated since 1999. (Unless lines have been added and then removed.)

So I wonder if this specific function could be marked unsafe again?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions