- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Encode hashes as bytes, not varint #110083
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
Conversation
| @bors try @rust-timer queue | 
      
        
              This comment has been minimized.
        
        
      
    
  This comment has been minimized.
| ⌛ Trying commit 8627fe1a80c6f8cabc961d8ca7df3d05a61e956a with merge 6de33b85fc2e7dfa93da079f1e2e5b09b9fd618b... | 
      
        
              This comment has been minimized.
        
        
      
    
  This comment has been minimized.
| ☀️ Try build successful - checks-actions | 
      
        
              This comment has been minimized.
        
        
      
    
  This comment has been minimized.
| I don't think hash should be defined as bytes -- doing so reduces alignment and can be detrimental (especially on platforms that don't have efficient misaligned memory access). Also on 32-bit platforms, they now have to be passed via memory. If this is only about encoding then a new type with custom  | 
| Finished benchmarking commit (6de33b85fc2e7dfa93da079f1e2e5b09b9fd618b): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment. 
 Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment. 
 CyclesThis benchmark run did not return any relevant results for this metric. | 
| Cachegrind diff for the one benchmark with significant improvement says: Which is not what I would have predicted. Interesting. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which is not what I would have predicted. Interesting.
Maybe the hashes for type-ids? u*::MAX constants?
8627fe1    to
    5118a86      
    Compare
  
    | I've touched a lot more code now... | 
      
        
              This comment has been minimized.
        
        
      
    
  This comment has been minimized.
| ⌛ Trying commit 5118a860452ba5c8d48159ddaa18febcae879b37 with merge 4dc92c4e8ab0d1196d7c7b485a13ce4cbe848b4b... | 
      
        
              This comment has been minimized.
        
        
      
    
  This comment has been minimized.
caec88f    to
    16ada86      
    Compare
  
    | Once more, with feeling | 
      
        
              This comment has been minimized.
        
        
      
    
  This comment has been minimized.
| ⌛ Trying commit 16ada86621692739ee72861fb9c15043f1d27768 with merge e89b3eb207a1843d10eccc438536aeca22752ecf... | 
| ☀️ Try build successful - checks-actions | 
| Rebased over #110343 to simplify the distributions in the PR description. | 
6df4b53    to
    a04c09a      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would a few inlines be helpful?
r=me either way
Co-authored-by: Camille Gillot <gillot.camille@gmail.com>
| @bors r+ | 
| ☀️ Test successful - checks-actions | 
| Finished benchmarking commit (b3f1379): comparison URL. Overall result: ❌✅ regressions and improvements - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment. 
 Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment. 
 CyclesThis benchmark run did not return any relevant results for this metric. | 
…workingjubilee Replace some u64 hashes with Hash64 I introduced the Hash64 and Hash128 types in rust-lang#110083, essentially as a mechanism to prevent hashes from landing in our leb128 encoding paths. If you just have a u64 or u128 field in a struct then derive Encodable/Decodable, that number gets leb128 encoding. So if you need to store a hash or some other value which behaves very close to a hash, don't store it as a u64. This reverts part of rust-lang#117603, which turned an encoded Hash64 into a u64. Based on rust-lang#110083, I don't expect this to be perf-sensitive on its own, though I expect that it may help stabilize some of the small rmeta size fluctuations we currently see in perf reports.
…workingjubilee Replace some u64 hashes with Hash64 I introduced the Hash64 and Hash128 types in rust-lang#110083, essentially as a mechanism to prevent hashes from landing in our leb128 encoding paths. If you just have a u64 or u128 field in a struct then derive Encodable/Decodable, that number gets leb128 encoding. So if you need to store a hash or some other value which behaves very close to a hash, don't store it as a u64. This reverts part of rust-lang#117603, which turned an encoded Hash64 into a u64. Based on rust-lang#110083, I don't expect this to be perf-sensitive on its own, though I expect that it may help stabilize some of the small rmeta size fluctuations we currently see in perf reports.
Rollup merge of rust-lang#137095 - saethlin:use-hash64-for-hashes, r=workingjubilee Replace some u64 hashes with Hash64 I introduced the Hash64 and Hash128 types in rust-lang#110083, essentially as a mechanism to prevent hashes from landing in our leb128 encoding paths. If you just have a u64 or u128 field in a struct then derive Encodable/Decodable, that number gets leb128 encoding. So if you need to store a hash or some other value which behaves very close to a hash, don't store it as a u64. This reverts part of rust-lang#117603, which turned an encoded Hash64 into a u64. Based on rust-lang#110083, I don't expect this to be perf-sensitive on its own, though I expect that it may help stabilize some of the small rmeta size fluctuations we currently see in perf reports.
…bilee Replace some u64 hashes with Hash64 I introduced the Hash64 and Hash128 types in rust-lang/rust#110083, essentially as a mechanism to prevent hashes from landing in our leb128 encoding paths. If you just have a u64 or u128 field in a struct then derive Encodable/Decodable, that number gets leb128 encoding. So if you need to store a hash or some other value which behaves very close to a hash, don't store it as a u64. This reverts part of rust-lang/rust#117603, which turned an encoded Hash64 into a u64. Based on rust-lang/rust#110083, I don't expect this to be perf-sensitive on its own, though I expect that it may help stabilize some of the small rmeta size fluctuations we currently see in perf reports.
…bilee Replace some u64 hashes with Hash64 I introduced the Hash64 and Hash128 types in rust-lang/rust#110083, essentially as a mechanism to prevent hashes from landing in our leb128 encoding paths. If you just have a u64 or u128 field in a struct then derive Encodable/Decodable, that number gets leb128 encoding. So if you need to store a hash or some other value which behaves very close to a hash, don't store it as a u64. This reverts part of rust-lang/rust#117603, which turned an encoded Hash64 into a u64. Based on rust-lang/rust#110083, I don't expect this to be perf-sensitive on its own, though I expect that it may help stabilize some of the small rmeta size fluctuations we currently see in perf reports.
In a few places, we store hashes as
u64oru128and then applyderive(Decodable, Encodable)to the enclosing struct/enum. It is more efficient to encode hashes directly than try to apply some varint encoding. This PR adds two new typesHash64andHash128which are produced byStableHasherand replace every use of storing au64oru128that represents a hash.Distribution of the byte lengths of leb128 encodings, from
x build --stage 2withincremental = trueBefore:
After:
The remaining 9 or 10 and 18 or 19 are
u64andu128respectively that have the high bits set. As far as I can tell these are coming primarily fromSwitchTargets.