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

GC-related optimizations #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

casept
Copy link

@casept casept commented May 7, 2024

  • Remove manual GC calls, these shouldn't be needed anymore as the Go runtime now manages low-memory situations better
  • Significantly reduce the amount of garbage generated in hot functions, leading to speedups of about 25%

casept added 5 commits May 7, 2024 04:11
Passing the Fields interface into the readX functions results
in the passed-in struct being copied, creating an object that
needs to be cleaned up by GC later.

This results in a large part of program runtime being spent on
GC, as this function is used in many hot functions, such as
createStopTime().

According to pprof, removing these copies speeds up the entire
program by about 14%, and reduces the amount of garbage objects generated
by over 25%.
This function is on a hot path and previosuly used
string.Split, which allocates a string slice and therefore
produces a lot of garbage.

Replace with strings.Cut, which doesn't allocate.
The sole caller only uses one field, and by returning this field
directly we allow Go's escape analysis to do it's thing and avoid
a costly heap allocation. According to pprof, this cuts out
several million allocations when parsing the German GTFS dataset.

This function is not exported, therefore this change does not alter the public API.
The logic to apply custom headsigns seems broken anyways,
as the ID is negative and the field is not marked required,
leading to getString() always returning the empty string.

According to pprof, this reduces GC usage by 25%
and speeds up gtfstidy by 6%.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant