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

Small optimizations in macro derive #80259

Closed
wants to merge 4 commits into from

Conversation

JulianKnodt
Copy link
Contributor

Some small memory optimizations in macro derives, removing some allocations.

@rust-highfive
Copy link
Collaborator

r? @davidtwco

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 21, 2020
@davidtwco
Copy link
Member

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@bors
Copy link
Contributor

bors commented Dec 21, 2020

⌛ Trying commit 0e41d272039134a34d06081c4cb9536d646ec019 with merge daac1498047258893dc86ee7a1f908737a5cbb90...

Copy link
Member

@davidtwco davidtwco left a comment

Choose a reason for hiding this comment

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

Implementation LGTM, queued a perf run, r=me if there's an improvement.

@bors
Copy link
Contributor

bors commented Dec 21, 2020

☀️ Try build successful - checks-actions
Build commit: daac1498047258893dc86ee7a1f908737a5cbb90 (daac1498047258893dc86ee7a1f908737a5cbb90)

@rust-timer
Copy link
Collaborator

Queued daac1498047258893dc86ee7a1f908737a5cbb90 with parent 463ce40, future comparison URL.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Dec 21, 2020
@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (daac1498047258893dc86ee7a1f908737a5cbb90): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Dec 21, 2020
@JulianKnodt
Copy link
Contributor Author

I believe this can only be chocked up to noise; if it's alright I'd like to continue working on this

@JulianKnodt
Copy link
Contributor Author

This should be good, hopefully it has a minor effect?

@davidtwco
Copy link
Member

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@bors
Copy link
Contributor

bors commented Dec 22, 2020

⌛ Trying commit 35299bc07437135d217c19074d62693c74db6caa with merge 43e292cf8756d483a054508a0149e128ec285434...

@bors
Copy link
Contributor

bors commented Dec 22, 2020

☀️ Try build successful - checks-actions
Build commit: 43e292cf8756d483a054508a0149e128ec285434 (43e292cf8756d483a054508a0149e128ec285434)

@rust-timer
Copy link
Collaborator

Queued 43e292cf8756d483a054508a0149e128ec285434 with parent 353f3a3, future comparison URL.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Dec 22, 2020
@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (43e292cf8756d483a054508a0149e128ec285434): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Dec 23, 2020
@JulianKnodt
Copy link
Contributor Author

Hm, I can't make heads or tails of whether this is just noise at this point(which probably means it is noise), but let me know what you think.

@davidtwco
Copy link
Member

Hm, I can't make heads or tails of whether this is just noise at this point(which probably means it is noise), but let me know what you think.

I agree, it's hard to say if there's any improvement here. If you have other things that you want to try then feel free to, but we might just need to close this unfortunately.

@JulianKnodt
Copy link
Contributor Author

I'll keep working on it, but will try to avoid perf runs for a bit

@JulianKnodt
Copy link
Contributor Author

JulianKnodt commented Dec 25, 2020

I believe this should certainly have some perf impact now, altho it's deviated a bit from the original course of the PR

I think a lot of the original optimizations were on cold-paths, so they're not noticeable in the benchmarks but aren't bad either.
I attempted to fix something which is more on the hot-path, which was changing the functions on AstConv to no longer be dyn, which is likely slower and unnecessary as compared to implementing it on implementors of AstConv. I'm not sure about the style I have, but it should be faster.

@davidtwco
Copy link
Member

Sorry for the delay in getting back to this, @JulianKnodt: I'll trigger another try and perf run, but could you rebase first (I think the try run will fail otherwise)?

@davidtwco davidtwco added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 31, 2020
@JulianKnodt
Copy link
Contributor Author

No worries, it's the holidays and all, thank you for helping out even w/ me implementing somewhat random optimizations

@bors
Copy link
Contributor

bors commented Jan 1, 2021

☔ The latest upstream changes (presumably #80547) made this pull request unmergeable. Please resolve the merge conflicts.

More minor opts

Rm unnecessary boxes
Really just one batched allocation, and the rest are style changes
I expect this to have a perf impact because I think this is responsible for lowering types from
hir, and that the reason that lowering builtin derives is slow is because the paths are longer.
That lead me to find this, which I'm not sure if this is on the hot path or not. If it is, this
should certainly be a perf win.
@rust-log-analyzer
Copy link
Collaborator

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
    Checking rustc_mir v0.0.0 (/checkout/compiler/rustc_mir)
    Checking rustc_passes v0.0.0 (/checkout/compiler/rustc_passes)
    Checking rustc_traits v0.0.0 (/checkout/compiler/rustc_traits)
    Checking rustc_mir_build v0.0.0 (/checkout/compiler/rustc_mir_build)
error[E0425]: cannot find function `check_generic_arg_count_for_call` in module `astconv::generics`
    --> compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs:1232:36
     |
1232 |               } = astconv::generics::check_generic_arg_count_for_call(
     |                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: a function with a similar name exists: `check_generic_arg_count`
    ::: compiler/rustc_typeck/src/astconv/generics.rs:338:1
     |
     |
338  | / pub(crate) fn check_generic_arg_count(
339  | |     tcx: TyCtxt<'_>,
340  | |     span: Span,
341  | |     def: &ty::Generics,
480  | |     }
481  | | }
481  | | }
     | |_- similarly named function `check_generic_arg_count` defined here

error[E0425]: cannot find function `check_generic_arg_count_for_call` in module `astconv::generics`
   --> compiler/rustc_typeck/src/check/method/confirm.rs:301:52
    |
301 |           let arg_count_correct = astconv::generics::check_generic_arg_count_for_call(
    |                                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: a function with a similar name exists: `check_generic_arg_count`
   ::: compiler/rustc_typeck/src/astconv/generics.rs:338:1
    |
    |
338 | / pub(crate) fn check_generic_arg_count(
339 | |     tcx: TyCtxt<'_>,
340 | |     span: Span,
341 | |     def: &ty::Generics,
480 | |     }
481 | | }
481 | | }
    | |_- similarly named function `check_generic_arg_count` defined here
    Checking rustc_plugin_impl v0.0.0 (/checkout/compiler/rustc_plugin_impl)
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0425`.
For more information about this error, try `rustc --explain E0425`.
error: could not compile `rustc_typeck`

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed
command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "check" "--target" "x86_64-unknown-linux-gnu" "-Zbinary-dep-depinfo" "-j" "16" "--release" "--color" "always" "--features" " llvm max_level_info" "--manifest-path" "/checkout/compiler/rustc/Cargo.toml" "-p" "rustc-main" "-p" "rustc_driver" "-p" "rustc_lint" "-p" "rustc_index" "-p" "rustc_macros" "-p" "rustc_trait_selection" "-p" "rustc_infer" "-p" "rustc_graphviz" "-p" "rustc_parse_format" "-p" "rustc_lexer" "-p" "rustc_attr" "-p" "rustc_span" "-p" "rustc_arena" "-p" "rustc_save_analysis" "-p" "rustc_feature" "-p" "rustc_errors" "-p" "rustc_lint_defs" "-p" "rustc_ast" "-p" "rustc_middle" "-p" "rustc_query_system" "-p" "rustc_apfloat" "-p" "rustc_type_ir" "-p" "rustc_metadata" "-p" "rustc_expand" "-p" "rustc_ast_passes" "-p" "rustc_parse" "-p" "rustc_data_structures" "-p" "rustc_ast_pretty" "-p" "rustc_hir_pretty" "-p" "rustc_interface" "-p" "rustc_passes" "-p" "rustc_resolve" "-p" "rustc_codegen_llvm" "-p" "rustc_fs_util" "-p" "rustc_llvm" "-p" "rustc_typeck" "-p" "rustc_incremental" "-p" "rustc_traits" "-p" "rustc_privacy" "-p" "rustc_builtin_macros" "-p" "rustc_symbol_mangling" "-p" "rustc_mir_build" "-p" "rustc_ast_lowering" "-p" "rustc_ty_utils" "-p" "rustc_target" "-p" "rustc_mir" "-p" "coverage_test_macros" "-p" "rustc_session" "-p" "rustc_hir" "-p" "rustc_serialize" "-p" "rustc_error_codes" "-p" "rustc_plugin_impl" "-p" "rustc_codegen_ssa" "--message-format" "json-render-diagnostics"
failed to run: /checkout/obj/build/bootstrap/debug/bootstrap check
Build completed unsuccessfully in 0:02:51

Remove one unnecessary collect at the end of a fn
@davidtwco
Copy link
Member

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@bors
Copy link
Contributor

bors commented Jan 2, 2021

⌛ Trying commit d6695bd with merge 61d0d1bc1c119080c4722bd97a803af5207e6ab5...

@bors
Copy link
Contributor

bors commented Jan 2, 2021

☀️ Try build successful - checks-actions
Build commit: 61d0d1bc1c119080c4722bd97a803af5207e6ab5 (61d0d1bc1c119080c4722bd97a803af5207e6ab5)

@rust-timer
Copy link
Collaborator

Queued 61d0d1bc1c119080c4722bd97a803af5207e6ab5 with parent 90ccf4f, future comparison URL.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 2, 2021
@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (61d0d1bc1c119080c4722bd97a803af5207e6ab5): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jan 2, 2021
@JulianKnodt
Copy link
Contributor Author

Let me know what you think of these results, some are p good but it's mixed.
If they're not significant I'll just toss out all the changes

@davidtwco
Copy link
Member

Let me know what you think of these results, some are p good but it's mixed.
If they're not significant I'll just toss out all the changes

The max-rss results, while initially promising, are probably just noise (when compared to the last noise run). Unfortunately, I don't think these results are significant. Thanks for taking the time to try make an improvement here though!

@JulianKnodt JulianKnodt closed this Jan 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants