1. 25 Nov, 2015 13 commits
    • Caleb Spare's avatar
      regexp: fix one-pass compilation · e36bf614
      Caleb Spare authored
      The one-pass transformation is structured as a search over the input
      machine for conditions that violate the one-pass requisites. At each
      iteration, we should fully explore all non-input paths that proceed from
      the current instruction; this is implemented via recursive check calls.
      But when we reach instructions that demand input (InstRune*), these
      should be put onto the search queue.
      
      Instead of searching this way, the routine previously (effectively)
      proceeded through the machine one instruction at a time until finding an
      Inst{Match,Fail,Rune*}, calling check on each instruction. This caused
      bug #11905, where the transformation stopped before rewriting all
      InstAlts as InstAltMatches.
      
      Further, the check function unnecessarily recurred on InstRune*
      instructions. (I believe this helps to mask the above bug.)
      
      This change also deletes some unused functions and duplicate test cases.
      
      Fixes #11905.
      
      Change-Id: I5b0b26efea3d3bd01c7479a518b5ed1b886701cd
      Reviewed-on: https://go-review.googlesource.com/17195Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
      e36bf614
    • Caleb Spare's avatar
      regexp: fix LiteralPrefix for certain onepass progs · d1eedfe1
      Caleb Spare authored
      The prefix computation for onepass was incorrectly returning
      complete=true when it encountered a beginning-of-text empty width match
      (^) in the middle of an expression.
      
      Fix by returning complete only when the prefix is followed by $ and then
      an accepting state.
      
      Fixes #11175.
      
      Change-Id: Ie9c4cf5f76c1d2c904a6fb2f016cedb265c19fde
      Reviewed-on: https://go-review.googlesource.com/16200
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
      d1eedfe1
    • Caleb Spare's avatar
      regexp: add Copy method to Regexp · 937172b2
      Caleb Spare authored
      This helps users who wish to use separate Regexps in each goroutine to
      avoid lock contention. Previously they had to parse the expression
      multiple times to achieve this.
      
      I used variants of the included benchmark to evaluate this change. I
      used the arguments -benchtime 20s -cpu 1,2,4,8,16 on a machine with 16
      hardware cores.
      
      Comparing a single shared Regexp vs. copied Regexps, we can see that
      lock contention causes huge slowdowns at higher levels of parallelism.
      The copied version shows the expected linear speedup.
      
      name              old time/op  new time/op  delta
      MatchParallel      366ns ± 0%   370ns ± 0%   +1.09%   (p=0.000 n=10+8)
      MatchParallel-2    324ns ±28%   184ns ± 1%  -43.37%  (p=0.000 n=10+10)
      MatchParallel-4    352ns ± 5%    93ns ± 1%  -73.70%   (p=0.000 n=9+10)
      MatchParallel-8    480ns ± 3%    46ns ± 0%  -90.33%    (p=0.000 n=9+8)
      MatchParallel-16   510ns ± 8%    24ns ± 6%  -95.36%   (p=0.000 n=10+8)
      
      I also compared a modified version of Regexp that has no mutex and a
      single machine (the "RegexpForSingleGoroutine" rsc mentioned in
      https://github.com/golang/go/issues/8232#issuecomment-66096128).
      
      In this next test, I compared using N copied Regexps vs. N separate
      RegexpForSingleGoroutines. This shows that, even for this relatively
      simple regex, avoiding the lock entirely would only buy about 10-12%
      further improvement.
      
      name              old time/op  new time/op  delta
      MatchParallel      370ns ± 0%   322ns ± 0%  -12.97%    (p=0.000 n=8+8)
      MatchParallel-2    184ns ± 1%   162ns ± 1%  -11.60%  (p=0.000 n=10+10)
      MatchParallel-4   92.7ns ± 1%  81.1ns ± 2%  -12.43%  (p=0.000 n=10+10)
      MatchParallel-8   46.4ns ± 0%  41.8ns ±10%   -9.78%   (p=0.000 n=8+10)
      MatchParallel-16  23.7ns ± 6%  20.6ns ± 1%  -13.14%    (p=0.000 n=8+8)
      
      Updates #8232.
      
      Change-Id: I15201a080c363d1b44104eafed46d8df5e311902
      Reviewed-on: https://go-review.googlesource.com/16110Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
      937172b2
    • Tamir Duberstein's avatar
      regexp/syntax: correctly print `^` BOL and `$` EOL · 3aa755b8
      Tamir Duberstein authored
      Fixes #12980.
      
      Change-Id: I936db2f57f7c4dc80bb8ec32715c4c6b7bf0d708
      Reviewed-on: https://go-review.googlesource.com/16112Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
      3aa755b8
    • Giulio Iotti's avatar
      encoding/xml: case-insensitive encoding recognition · 0b55be1b
      Giulio Iotti authored
      From the XML spec: "XML processors should match character encoding
      names in a case-insensitive way"
      
      Fixes #12417.
      
      Change-Id: I678c50152a49c14364be62b3f21ab9b9b009b24b
      Reviewed-on: https://go-review.googlesource.com/14084Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
      0b55be1b
    • Michal Bohuslávek's avatar
      encoding/xml: reject invalid comments · 97c859f8
      Michal Bohuslávek authored
      Fixes #11112.
      
      Change-Id: I16e7363549a0dec8c61addfa14af0866c1fd7c40
      Reviewed-on: https://go-review.googlesource.com/14173Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
      97c859f8
    • Charles Weill's avatar
      encoding/xml: Add CDATA-wrapper output support to xml.Marshal. · 3f6b91b1
      Charles Weill authored
      Fixes #12963
      
      Change-Id: Icc50dfb6130fe1e189d45f923c2f7408d3cf9401
      Reviewed-on: https://go-review.googlesource.com/16047Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
      3f6b91b1
    • Aliaksandr Valialkin's avatar
      encoding/gob: reduce the amount of memory allocations. · a48de745
      Aliaksandr Valialkin authored
      Benchmark results:
      
      benchmark                              old ns/op     new ns/op     delta
      BenchmarkEndToEndPipe-4                7547          7294          -3.35%
      BenchmarkEndToEndByteBuffer-4          5146          5092          -1.05%
      BenchmarkEndToEndSliceByteBuffer-4     552779        439768        -20.44%
      BenchmarkEncodeComplex128Slice-4       266370        266184        -0.07%
      BenchmarkEncodeFloat64Slice-4          111891        110258        -1.46%
      BenchmarkEncodeInt32Slice-4            74482         74080         -0.54%
      BenchmarkEncodeStringSlice-4           84404         84279         -0.15%
      BenchmarkEncodeInterfaceSlice-4        3942925       3045995       -22.75%
      BenchmarkDecodeComplex128Slice-4       451837        415282        -8.09%
      BenchmarkDecodeFloat64Slice-4          283584        262558        -7.41%
      BenchmarkDecodeInt32Slice-4            246571        237383        -3.73%
      BenchmarkDecodeStringSlice-4           734210        479625        -34.67%
      BenchmarkDecodeInterfaceSlice-4        4778225       4160935       -12.92%
      
      benchmark                              old allocs     new allocs     delta
      BenchmarkEndToEndPipe-4                3              2              -33.33%
      BenchmarkEndToEndByteBuffer-4          3              2              -33.33%
      BenchmarkEndToEndSliceByteBuffer-4     1002           402            -59.88%
      BenchmarkEncodeComplex128Slice-4       1              1              +0.00%
      BenchmarkEncodeFloat64Slice-4          1              1              +0.00%
      BenchmarkEncodeInt32Slice-4            1              1              +0.00%
      BenchmarkEncodeStringSlice-4           1              1              +0.00%
      BenchmarkEncodeInterfaceSlice-4        3001           1              -99.97%
      BenchmarkDecodeComplex128Slice-4       188            185            -1.60%
      BenchmarkDecodeFloat64Slice-4          188            185            -1.60%
      BenchmarkDecodeInt32Slice-4            188            185            -1.60%
      BenchmarkDecodeStringSlice-4           2188           1185           -45.84%
      BenchmarkDecodeInterfaceSlice-4        6197           4194           -32.32%
      
      benchmark                              old bytes     new bytes     delta
      BenchmarkEndToEndPipe-4                64            48            -25.00%
      BenchmarkEndToEndByteBuffer-4          64            48            -25.00%
      BenchmarkEndToEndSliceByteBuffer-4     34551         10554         -69.45%
      BenchmarkEncodeComplex128Slice-4       55            55            +0.00%
      BenchmarkEncodeFloat64Slice-4          33            33            +0.00%
      BenchmarkEncodeInt32Slice-4            32            32            +0.00%
      BenchmarkEncodeStringSlice-4           36            36            +0.00%
      BenchmarkEncodeInterfaceSlice-4        144555        347           -99.76%
      BenchmarkDecodeComplex128Slice-4       28240         28097         -0.51%
      BenchmarkDecodeFloat64Slice-4          11840         11697         -1.21%
      BenchmarkDecodeInt32Slice-4            10817         10673         -1.33%
      BenchmarkDecodeStringSlice-4           56128         39985         -28.76%
      BenchmarkDecodeInterfaceSlice-4        132565        100421        -24.25%
      
      Change-Id: Ief7c7706b1f2916486ab7190b81aafbb16b70f1e
      Reviewed-on: https://go-review.googlesource.com/13660Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
      a48de745
    • Erik Dubbelboer's avatar
      encoding/json: check if Number is valid · c4be790c
      Erik Dubbelboer authored
      json.Number is a special case which didn't have any checks and could result in invalid JSON.
      
      Fixes #10281
      
      Change-Id: Ie3e726e4d6bf6a6aba535d36f6107013ceac913a
      Reviewed-on: https://go-review.googlesource.com/12250Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
      c4be790c
    • Joe Tsai's avatar
      hash/crc32: add noescape tags to assembly functions · 64cc5fd0
      Joe Tsai authored
      CRC-32 computation is stateless and the p slice does not get stored
      anywhere. Thus, we mark the assembly functions as noescape so that
      it doesn't believe that p leaks in:
      	func Update(crc uint32, tab *Table, p []byte) uint32
      
      Before:
      	./crc32.go:153: leaking param: p
      
      After:
      	./crc32.go:153: Update p does not escape
      
      Change-Id: I52ba35b6cc544fff724327140e0c27898431d1dc
      Reviewed-on: https://go-review.googlesource.com/17069Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
      64cc5fd0
    • Brad Fitzpatrick's avatar
      net/http: more HTTP/2 tests and fixes · e5956bca
      Brad Fitzpatrick authored
      This compares the behavior of server handlers and the net/http
      Transport in both HTTP/1 and HTTP/2 mode and verifies they're the
      same.
      
      This also moves some client<->server tests into clientserver_test.go.
      Many of them were in serve_test.go or transport_test.go but were
      basically testing both.
      
      h2_bundle.go is an update of the golang.org/x/net/http2 code
      from https://golang.org/cl/17204 (x/net git rev c745c36eab10)
      
      Fixes #13315
      Fixes #13316
      Fixes #13317
      Fixes other stuff found in the process too
      Updates #6891 (http2 support in general)
      
      Change-Id: Id9c45fad44cdf70ac95d2b89e578d66e882d3cc2
      Reviewed-on: https://go-review.googlesource.com/17205Reviewed-by: 's avatarAndrew Gerrand <adg@golang.org>
      Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
      e5956bca
    • Michael Hudson-Doyle's avatar
      runtime: fix conflict resolution in golang.org/cl/14207 · fd2bc868
      Michael Hudson-Doyle authored
      Fixes testshared on arm64 and ppc64le.
      
      Change-Id: Ie94bc0c85c7666fbb5ab6fc6d3dbb180407a9955
      Reviewed-on: https://go-review.googlesource.com/17212Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
      fd2bc868
    • Shenghou Ma's avatar
      runtime: check that masks and shifts are correct aligned · 3583a44e
      Shenghou Ma authored
      We need a runtime check because the original issue is encountered
      when running cross compiled windows program from linux. It's better
      to give a meaningful crash message earlier than to segfault later.
      
      The added test should not impose any measurable overhead to Go
      programs.
      
      For #12415.
      
      Change-Id: Ib4a24ef560c09c0585b351d62eefd157b6b7f04c
      Reviewed-on: https://go-review.googlesource.com/14207Reviewed-by: 's avatarKeith Randall <khr@golang.org>
      Run-TryBot: Minux Ma <minux@golang.org>
      TryBot-Result: Gobot Gobot <gobot@golang.org>
      3583a44e
  2. 24 Nov, 2015 25 commits
  3. 23 Nov, 2015 2 commits