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

perf: avoid mem alloc in formatting, minor bug fix #1521

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

nyurik
Copy link
Contributor

@nyurik nyurik commented Feb 4, 2024

Optimize writing formatted string to Serde, bypassing string allocations when possible.

Note that pgrx-sql-entity-graph/src/extension_sql/entity.rs seemed to have a bug for Function printing - it was printing Function name) without the opening parenthesis.

Also, in a few spots, I replaced buffer.write_fmt(format_args!(...)) with write!(buffer, ...) -- as that's exactly what write! macro is for.

@nyurik nyurik changed the title perf: optimize string formatting and minor bug fix perf: avoid mem alloc in formatting, minor bug fix Feb 4, 2024
@workingjubilee
Copy link
Member

Note that pgrx-sql-entity-graph/src/extension_sql/entity.rs seemed to have a bug for Function printing - it was printing Function name) without the opening parenthesis.

I don't see how the code could function with that being the case, so it seems possible this has just moved the bug around. I will have to take a closer look.

Optimize writing formatted string to Serde, bypassing string allocations when possible.

Note that `pgrx-sql-entity-graph/src/extension_sql/entity.rs` seemed to have a bug for Function printing - it was printing `Function name)` without the opening parenthesis.

Also, in a few spots, I replaced `buffer.write_fmt(format_args!(...))` with `write!(buffer, ...)` -- as that's exactly what `write!` macro is for.
}
SqlDeclaredEntity::Function(data) => {
f.write_str(&(String::from("Function ") + &data.name + ")"))
write!(f, "Function({})", data.name)
Copy link
Member

Choose a reason for hiding this comment

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

I can't actually find a case where this actually diffs a schema, and that is Worrying, because that suggests it is Simply Dead Code.

Copy link
Member

Choose a reason for hiding this comment

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

I did not exhaustively cover every extension in reach but I have reached the "I need to script out the schema generation delta check" part, which means I might as well bash out a v0.1 solution to #1521

Copy link
Contributor

@NotGyro NotGyro left a comment

Choose a reason for hiding this comment

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

This looks good to me. In addition to cutting out unnecessary allocations, this also makes the affected code more readable.

@nyurik
Copy link
Contributor Author

nyurik commented May 6, 2024

any updates on this?

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

3 participants