Commit Graph

254 Commits

Author SHA1 Message Date
bors 22f8bde876 Auto merge of #91549 - fee1-dead:const_env, r=spastorino
Eliminate ConstnessAnd again

Closes #91489.
Closes #89432.

Reverts #91491.
Reverts #89450.

r? `@spastorino`
2021-12-12 22:15:32 +00:00
Deadbeef 83587e8d30 Small performance tweaks 2021-12-12 12:35:01 +08:00
bors 58457bbfd3 Auto merge of #89404 - Kobzol:hash-stable-sort, r=Mark-Simulacrum
Slightly optimize hash map stable hashing

I was profiling some of the `rustc-perf` benchmarks locally and noticed that quite some time is spent inside the stable hash of hashmaps. I tried to use a `SmallVec` instead of a `Vec` there, which helped very slightly.

Then I tried to remove the sorting, which was a bottleneck, and replaced it with insertion into a binary heap. Locally, it yielded nice improvements in instruction counts and RSS in several benchmarks for incremental builds. The implementation could probably be much nicer and possibly extended to other stable hashes, but first I wanted to test the perf impact properly.

Can I ask someone to do a perf run? Thank you!
2021-12-12 03:50:30 +00:00
Matthias Krüger 7e18b79c77 Rollup merge of #91426 - eggyal:idfunctor-panic-safety, r=lcnr
Make IdFunctor::try_map_id panic-safe

Addresses FIXME comment created in #78313

r? ```@lcnr```
2021-12-11 08:22:32 +01:00
est31 15de4cbc4b Remove redundant [..]s 2021-12-09 00:01:29 +01:00
Alan Egerton acd39ff0fe Make IdFunctor::try_map_id panic-safe 2021-12-07 11:11:23 +00:00
Mark Rousskov 15483ccf9d Annotate comments onto the LT algorithm 2021-12-06 20:30:15 -05:00
Mark Rousskov 3187480070 Avoid using Option where values are always Some 2021-12-06 15:05:22 -05:00
Mark Rousskov 2b63059772 Create newtype around the pre order index 2021-12-06 15:05:22 -05:00
Mark Rousskov cc63ec32fb Use variables rather than lengths directly 2021-12-06 15:05:22 -05:00
Mark Rousskov 345ada0e1b Optimize: reuse the real-to-preorder mapping as the visited set 2021-12-06 15:05:22 -05:00
Mark Rousskov 8991002644 Remove separate RPO traversal
This integrates the preorder and postorder traversals into one.
2021-12-06 15:05:22 -05:00
Mark Rousskov 7d12767dc5 Use preorder indices for data structures
This largely avoids remapping from and to the 'real' indices, with the exception
of predecessor lookup and the final merge back, and is conceptually better.
2021-12-06 15:05:22 -05:00
Mark Rousskov 92186cb5c9 Avoid inserting into buckets if not necessary 2021-12-06 15:05:22 -05:00
Mark Rousskov 7379d24ebc Optimization: process buckets only once 2021-12-06 15:05:22 -05:00
Mark Rousskov c82fe0efb4 Optimization: Merge parent and ancestor arrays
As the paper indicates, the unprocessed vertices in the DFS tree and processed
vertices are disjoint, and we can use them in the same space, tracking only the index
of the split.
2021-12-06 15:05:22 -05:00
Mark Rousskov e8d7248093 Implement the simple Lengauer-Tarjan algorithm
This replaces the previous implementation with the simple variant of
Lengauer-Tarjan, which performs better in the general case. Performance on the
keccak benchmark is about equivalent between the two, but we don't see
regressions (and indeed see improvements) on other benchmarks, even on a
partially optimized implementation.

The implementation here follows that of the pseudocode in "Linear-Time
Algorithms for Dominators and Related Problems" thesis by Loukas Georgiadis. The
next few commits will optimize the implementation as suggested in the thesis.
Several related works are cited in the comments within the implementation, as
well.

Implement the simple Lengauer-Tarjan algorithm

This replaces the previous implementation (from #34169), which has not been
optimized since, with the simple variant of Lengauer-Tarjan which performs
better in the general case. A previous attempt -- not kept in commit history --
attempted a replacement with a bitset-based implementation, but this led to
regressions on perf.rust-lang.org benchmarks and equivalent wins for the keccak
benchmark, so was rejected.

The implementation here follows that of the pseudocode in "Linear-Time
Algorithms for Dominators and Related Problems" thesis by Loukas Georgiadis. The
next few commits will optimize the implementation as suggested in the thesis.
Several related works are cited in the comments within the implementation, as
well.

On the keccak benchmark, we were previously spending 15% of our cycles computing
the NCA / intersect function; this function is quite expensive, especially on
modern CPUs, as it chases pointers on every iteration in a tight loop. With this
commit, we spend ~0.05% of our time in dominator computation.
2021-12-06 15:03:09 -05:00
Scott McMurray 308fd59f42 Stop enabling in_band_lifetimes in rustc_data_structures
There's a conversation in the tracking issue about possibly unaccepting `in_band_lifetimes`, but it's used heavily in the compiler, and thus there'd need to be a bunch of PRs like this if that were to happen.

So here's one to see how much of an impact it has.

(Oh, and I removed `nll` while I was here too, since it didn't seem needed.  Let me know if I should put that back.)
2021-12-05 20:17:35 -08:00
Matthias Krüger 31003a3089 Rollup merge of #88906 - Kixunil:box-maybe-uninit-write, r=dtolnay
Implement write() method for Box<MaybeUninit<T>>

This adds method similar to `MaybeUninit::write` main difference being
it returns owned `Box`. This can be used to elide copy from stack
safely, however it's not currently tested that the optimization actually
occurs.

Analogous methods are not provided for `Rc` and `Arc` as those need to
handle the possibility of sharing. Some version of them may be added in
the future.

This was discussed in #63291 which this change extends.
2021-12-03 06:24:11 +01:00
Martin Habovstiak 41e21aa1c2 Implement write() method for Box<MaybeUninit<T>>
This adds method similar to `MaybeUninit::write` main difference being
it returns owned `Box`. This can be used to elide copy from stack
safely, however it's not currently tested that the optimization actually
occurs.

Analogous methods are not provided for `Rc` and `Arc` as those need to
handle the possibility of sharing. Some version of them may be added in
the future.

This was discussed in #63291 which this change extends.
2021-12-02 17:18:34 +01:00
Alan Egerton db7295fa96 Remove no-longer used IdFunctor::map_id 2021-12-02 15:45:40 +00:00
Alan Egerton afa6f92c46 Use intrinsic pointer methods 2021-11-27 16:59:18 +00:00
Alan Egerton 9f714ef035 Delegate from map_id to try_map_id 2021-11-27 16:55:21 +00:00
Alan Egerton 04f1c09f90 Avoid UB when short-circuiting try_map_id for Vec 2021-11-27 15:06:06 +00:00
LeSeulArtichaut 6e3fa20b00 Make TypeFoldable implementors short-circuit on error
Co-authored-by: Alan Egerton <eggyal@gmail.com>
2021-11-26 07:17:59 +00:00
Yuki Okushi 8d4fbc9a73 Add #[inline]s to SortedIndexMultiMap 2021-11-11 08:35:59 +09:00
Matthias Krüger 5c454551da more clippy fixes 2021-11-07 16:59:05 +01:00
bors 88a5a984fe Auto merge of #90380 - Mark-Simulacrum:revert-89558-query-stable-lint, r=lcnr
Revert "Add rustc lint, warning when iterating over hashmaps"

Fixes perf regressions introduced in https://github.com/rust-lang/rust/pull/90235 by temporarily reverting the relevant PR.
2021-10-29 04:55:51 +00:00
Mark Rousskov 3215eeb99f Revert "Add rustc lint, warning when iterating over hashmaps" 2021-10-28 11:01:42 -04:00
bors c4ff03f689 Auto merge of #90145 - cjgillot:sorted-map, r=michaelwoerister
Use SortedMap in HIR.

Closes https://github.com/rust-lang/rust/issues/89788
r? `@ghost`
2021-10-28 13:04:40 +00:00
bors 235d9853d8 Auto merge of #90042 - pietroalbini:1.56-master, r=Mark-Simulacrum
Bump bootstrap compiler to 1.57

Fixes https://github.com/rust-lang/rust/issues/90152

r? `@Mark-Simulacrum`
2021-10-25 11:31:47 +00:00
Jakub Beránek e4b4d18f58 Use SmallVec in Hash map stable hashing 2021-10-25 08:26:00 +02:00
Matthias Krüger 87822b27ee Rollup merge of #89558 - lcnr:query-stable-lint, r=estebank
Add rustc lint, warning when iterating over hashmaps

r? rust-lang/wg-incr-comp
2021-10-24 15:48:42 +02:00
Pietro Albini b63ab8005a update cfg(bootstrap) 2021-10-23 21:55:57 -04:00
Mark Rousskov 3cd5c95ab0 Specialize HashStable for [u8] slices
Particularly for ctfe-stress-4, the hashing of byte slices as part of the
MIR Allocation is quite hot. Previously, we were falling back on byte-by-byte
copying of the slice into the SipHash buffer (64 bytes long) before hashing a 64
byte chunk, and then doing that again and again.

This should hopefully be an improvement for that code.
2021-10-23 12:11:05 -04:00
Camille GILLOT 6f6fa8b954 Use SortedMap in HIR. 2021-10-21 23:08:57 +02:00
lcnr 00e5abe9b6 allow potential_query_instability everywhere 2021-10-15 10:58:18 +02:00
Clemens Wasser b8c151c9d2 Remove for loop range 2021-10-10 16:32:16 +02:00
Clemens Wasser 71dd0b928b Apply clippy suggestions 2021-10-10 15:38:19 +02:00
Ryan Levick 757f76ef73 Update to measureme v10 2021-10-07 15:08:44 +02:00
Ryan Levick 947a33bf20 Add support for artifact size profiling 2021-10-07 14:22:29 +02:00
Jubilee 99e6e3ff07 Rollup merge of #87993 - kornelski:try_reserve_stable, r=joshtriplett
Stabilize try_reserve

Stabilization PR for the [`try_reserve` feature](https://github.com/rust-lang/rust/issues/48043#issuecomment-898040475).
2021-10-04 21:12:33 -07:00
Jubilee 9866b090f4 Rollup merge of #89508 - jhpratt:stabilize-const_panic, r=joshtriplett
Stabilize `const_panic`

Closes #51999

FCP completed in #89006

```@rustbot``` label +A-const-eval +A-const-fn +T-lang

cc ```@oli-obk``` for review (not `r?`'ing as not on lang team)
2021-10-04 13:58:17 -07:00
Kornel 00152d8977 Stabilize try_reserve 2021-10-04 10:29:46 +01:00
Jacob Pratt bce8621983 Stabilize const_panic 2021-10-04 02:33:33 -04:00
bjorn3 83ddedf170 Remove various unused feature gates 2021-10-02 19:09:18 +02:00
Oli Scherer 9b5aa063d8 More tracing instrumentation 2021-09-28 12:28:22 +00:00
Manish Goregaokar 653dcaac2b Rollup merge of #89216 - r00ster91:bigo, r=dtolnay
Consistent big O notation

This makes the big O time complexity notation in places with markdown support more consistent.
Inspired by #89210
2021-09-25 18:22:20 -07:00
Ellen f1e71a5b41 arrr caught ya caller
awd
2021-09-25 00:34:02 +01:00
r00ster91 956f87fb04 consistent big O notation 2021-09-24 12:44:28 +02:00