Allow table name to be Symbol or String, remove run from macros #660
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I had heard that using
run
in macros slowed down compilation times. Turns out, it's true!I ran benchmarks on master and this branch (
hyperfine --warmup 3 'crystal build --release spec/model_spec.cr'
)master: 5.016 seconds (average)
with these changes: 4.156 seconds (average)
That's a 17% improvement in release compile time!
Changes
Our only use for
run
was to infer the table name in migrations and in the models. We turned the model name into a symbol that was the table name. We only ever needed this info at runtime so it made sense to bring the code that was in the file beingrun
. The only problem is that we can't return a symbol anymore because the table name isn't determined until runtime and it's not possible to construct symbols at runtime. I added aTableName
alias that is justString | Symbol
and updated everywhere that takes in a table name to use it. I also found that all the places we were usingModel::TABLE_NAME
could be replaced by the class methodModel.table_name
so I removed the constant as well.