annotaterb icon indicating copy to clipboard operation
annotaterb copied to clipboard

Cache retrieved indexes in ModelWrapper

Open tr4b4nt opened this issue 8 months ago • 0 comments

When upgrading rails project with 200+ models from annotate to this gem (thanks for creating and maintaining it!), we noticed that annotation became a lot slower. We managed to pinpoint the problem to indexes = @klass.connection.indexes(table_name) which was invoked from AnnotationBuilder::Annotation#columns for every column of every model.

Original annotate:

bundle exec annotate --models  7,72s user 0,82s system 68% cpu 12,553 total

Before this change:

bundle exec annotaterb models  27,14s user 2,19s system 60% cpu 48,816 total

After this change:

bundle exec annotaterb models  7,22s user 0,82s system 82% cpu 9,748 total

tr4b4nt avatar Apr 28 '25 14:04 tr4b4nt