When we last bumped dependencies in https://github.com/mattermost/mattermost/pull/30005, `assert.NotSame` for maps started failing because of the change in https://github.com/stretchr/testify/issues/1661. The reality was that the previous assertion was silently skipped, and just now reporting as much.
Here's an illustrative example:
```go
package main
import (
"maps"
"testing"
"github.com/stretchr/testify/assert"
)
func TestClonedMapsAreNotSame(t *testing.T) {
original := map[string]int{
"a": 1,
"b": 2,
"c": 3,
}
cloned := maps.Clone(original)
assert.NotSame(t, original, cloned)
}
func TestSameMaps(t *testing.T) {
original := map[string]int{
"a": 1,
"b": 2,
"c": 3,
}
cloned := original
assert.Same(t, original, cloned)
cloned["d"] = 4
assert.Same(t, original, cloned)
}
```
which fails with the following after the original dependency update:
```
--- FAIL: TestClonedMapsAreNotSame (0.00s)
main_test.go:19:
Error Trace: /Users/jesse/tmp/testify/main_test.go:19
Error: Both arguments must be pointers
Test: TestClonedMapsAreNotSame
--- FAIL: TestSameMaps (0.00s)
main_test.go:30:
Error Trace: /Users/jesse/tmp/testify/main_test.go:30
Error: Both arguments must be pointers
Test: TestSameMaps
main_test.go:33:
Error Trace: /Users/jesse/tmp/testify/main_test.go:33
Error: Both arguments must be pointers
Test: TestSameMaps
FAIL
FAIL testassertequal 0.149s
FAIL
```
However, instead of fixing the underlying issue, we took the address of those variables and kept using `assert.Same`. This isn't meaningful, since it doesn't directly compare the underlying pointers of the map objects in question, just the address of the pointers to those maps. Here's the output after taking the address (e.g. `&original` and `&cloned`):
```
--- FAIL: TestSameMaps (0.00s)
main_test.go:30:
Error Trace: /Users/jesse/tmp/testify/main_test.go:30
Error: Not same:
expected: 0x14000070170 &map[string]int{"a":1, "b":2, "c":3}
actual : 0x14000070178 &map[string]int{"a":1, "b":2, "c":3}
Test: TestSameMaps
main_test.go:33:
Error Trace: /Users/jesse/tmp/testify/main_test.go:33
Error: Not same:
expected: 0x14000070170 &map[string]int{"a":1, "b":2, "c":3, "d":4}
actual : 0x14000070178 &map[string]int{"a":1, "b":2, "c":3, "d":4}
Test: TestSameMaps
FAIL
FAIL testassertequal 0.157s
FAIL
```
They are obviously the same map, since modifying `cloned` modified the
original, yet `assert.Same` thinks they are different (because the
pointe values are indeed different). (`assert.NotSame` "passes", but for
the wrong reasons.)
To fix this, introduce `model.AssertNotSameMap` to check this correctly.
Marshalling a json.RawMessage is not zero overhead. Instead,
it compacts the raw message which starts to have an overhead
at scale.
https://github.com/golang/go/issues/33422
Since we have full control over the message constructed, we
can simply write the byte slice into the network stream.
This gives considerable performance boost.
```
goos: linux
goarch: amd64
pkg: github.com/mattermost/mattermost/server/public/model
cpu: Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
│ old.txt │ new_2.txt │
│ sec/op │ sec/op vs base │
EncodeJSON-8 1640.5n ± 2% 289.6n ± 1% -82.35% (p=0.000 n=10)
│ old.txt │ new_2.txt │
│ B/op │ B/op vs base │
EncodeJSON-8 528.0 ± 0% 503.0 ± 0% -4.73% (p=0.000 n=10)
│ old.txt │ new_2.txt │
│ allocs/op │ allocs/op vs base │
EncodeJSON-8 5.000 ± 0% 4.000 ± 0% -20.00% (p=0.000 n=10)
```
P.S. No concerns over changing the model API because we are
still using 0.x
https://mattermost.atlassian.net/browse/MM-54998
```release-note
Improve websocket event marshalling performance
```
https://mattermost.atlassian.net/browse/MM-52532
- Replace golint with revive
- Add makezero linter
- Fix all the required linter failures
Some issues in enterprise and public modules
are yet to be fixed. We send this to expediate things.