Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: lightningnetwork/lightning-onion
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e386a4b64297d7c5ff370c16ac9d893e79d700c0
Choose a base ref
...
head repository: lightningnetwork/lightning-onion
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b4b6a0359da93165ed0bfb27ee6a79ff4bb88d44
Choose a head ref
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on Apr 26, 2018

  1. Remove unnecessary allocations in HopData encode/decode methods

    By removing io.Writer and io.Reader abstraction from encode and decode
    methods, the following benchmars:
    
    old:
    
    func BenchmarkHopDataEncode(b *testing.B) {
    	hd := new(HopData)
    	for i := 0; i < b.N; i++ {
    		hd.Encode(ioutil.Discard)
    	}
    }
    
    type nopReader struct{}
    
    func (nopReader) Read(b []byte) (int, error) { return len(b), nil }
    
    func BenchmarkHopDataDecode(b *testing.B) {
    	hd := new(HopData)
    	src := nopReader{}
    	for i := 0; i < b.N; i++ {
    		hd.Decode(src)
    	}
    }
    
    new:
    
    func BenchmarkHopDataEncode(b *testing.B) {
    	hd := new(HopData)
    	dst := make([]byte, hopDataSize)
    	for i := 0; i < b.N; i++ {
    		hd.Encode(dst)
    	}
    }
    
    func BenchmarkHopDataDecode(b *testing.B) {
    	hd := new(HopData)
    	src := make([]byte, hopDataSize)
    	for i := 0; i < b.N; i++ {
    		err := hd.Decode(src)
    		if err != nil {
    			panic(err)
    		}
    	}
    }
    
    show the following insrease in performance:
    
    benchmark                    old ns/op     new ns/op     delta
    BenchmarkHopDataEncode-4     80.7          12.1          -85.01%
    
    benchmark                    old allocs     new allocs     delta
    BenchmarkHopDataEncode-4     3              0              -100.00%
    
    benchmark                    old bytes     new bytes     delta
    BenchmarkHopDataEncode-4     24            0             -100.00%
    
    benchmark                    old ns/op     new ns/op     delta
    BenchmarkHopDataDecode-4     218           9.77          -95.52%
    
    benchmark                    old allocs     new allocs     delta
    BenchmarkHopDataDecode-4     4              0              -100.00%
    
    benchmark                    old bytes     new bytes     delta
    BenchmarkHopDataDecode-4     56            0             -100.00%
    mrekucci committed Apr 26, 2018
    Configuration menu
    Copy the full SHA
    b4b6a03 View commit details
    Browse the repository at this point in the history
Loading