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

Performance regression from marking c_PQnfields safe #70

Open
ChickenProp opened this issue Jan 6, 2025 · 0 comments
Open

Performance regression from marking c_PQnfields safe #70

ChickenProp opened this issue Jan 6, 2025 · 0 comments

Comments

@ChickenProp
Copy link

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?

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

No branches or pull requests

1 participant