This is surprisingly memory expensive when Poll gets called a lot, such
as when syncing lots of small files generating itemstarted/itemfinished
events. It's line number three in this heap profile on the
TestBenchmarkManyFiles test:
jb@syno:~/src/github.com/syncthing/syncthing/test (master) $ go tool pprof ../bin/syncthing heap-13194.pprof
Entering interactive mode (type "help" for commands)
(pprof) top
80.91MB of 83.05MB total (97.42%)
Dropped 1024 nodes (cum <= 0.42MB)
Showing top 10 nodes out of 85 (cum >= 1.75MB)
flat flat% sum% cum cum%
32MB 38.53% 38.53% 32.01MB 38.54% github.com/syndtr/goleveldb/leveldb/memdb.New
22.16MB 26.68% 65.21% 22.16MB 26.68% github.com/syndtr/goleveldb/leveldb/util.(*BufferPool).Get
13.02MB 15.68% 80.89% 13.02MB 15.68% time.NewTimer
6.94MB 8.35% 89.24% 6.94MB 8.35% github.com/syndtr/goleveldb/leveldb/memdb.(*DB).Put
3.18MB 3.82% 93.06% 3.18MB 3.82% github.com/calmh/xdr.(*Reader).ReadBytesMaxInto
With this change the allocation is removed entirely.
This is a large source of output from the new lock logging, and it
doesn't seem to accomplish anything useful that I can see. Running
integration with the race detector to make sure...
Integers are for numbers, enabling arithmetic like subtractions and for
loops without getting shot in the foot. Unsigneds are for bitfields.
- "int" for numbers that will always be laughably smaller than four
billion, and where we don't care about the serialization format.
- "int32" for numbers that will always be laughably smaller than four
billion, and will be serialized to four bytes.
- "int64" for numbers that may approach four billion or will be
serialized to eight bytes.
- "uint32" and "uint64" for bitfields, depending on required number of
bits and serialization format. Likewise "uint8" and "uint16", although
rare in this project since they don't exist in XDR.
- "int8", "int16" and plain "uint" are almost never useful.
- Bug fix - use .Errorf() instead of .Error():
Before this change, an error message for failed tests in files/set_test.go
wrongly tried to use format strings in a call to .Error()
- Change event constants to be of type EventType rather than untyped integers.
- Slightly relax the locking for registry cache lookups:
For read access to Discover.registry we only need to take a read lock.
- Some cosmetic fixes.