Skip to content
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

lib/model: Optimize jobQueue performance and memory use #8023

Merged
merged 1 commit into from Oct 29, 2021

Conversation

greatroar
Copy link
Contributor

By truncating time.Time to an int64 nanosecond count, we lose the ability to precisely order timestamps before 1678 or after 2262, but we gain (linux/amd64, Go 1.17.1):

name                      old time/op    new time/op    delta
JobQueuePushPopDone10k-8    2.85ms ± 5%    2.29ms ± 2%  -19.80%  (p=0.000 n=20+18)
JobQueueBump-8              34.0µs ± 1%    29.8µs ± 1%  -12.35%  (p=0.000 n=19+19)

name                      old alloc/op   new alloc/op   delta
JobQueuePushPopDone10k-8    2.56MB ± 0%    1.76MB ± 0%  -31.31%  (p=0.000 n=18+13)

name                      old allocs/op  new allocs/op  delta
JobQueuePushPopDone10k-8      23.0 ± 0%      23.0 ± 0%     ~     (all equal)

Results for BenchmarkJobQueueBump are with the fixed version, which no longer depends on b.N for the amount of work performed. rand.Rand.Intn is cheap at ~10ns per iteration.

The choice in Go 1.16, the current minimum required version, is between seconds and nanoseconds. When Go 1.17 becomes the minimum, the time.Time.UnixMicro or UnixMilli methods can be used instead to strike a different balance between timescale and precision.

@greatroar
Copy link
Contributor Author

DeepSource wants crypto/rand to be used even in tests. That seems kind of extreme.

By truncating time.Time to an int64 nanosecond count, we lose the
ability to precisely order timestamps before 1678 or after 2262, but we
gain (linux/amd64, Go 1.17.1):

name                      old time/op    new time/op    delta
JobQueuePushPopDone10k-8    2.85ms ± 5%    2.29ms ± 2%  -19.80%  (p=0.000 n=20+18)
JobQueueBump-8              34.0µs ± 1%    29.8µs ± 1%  -12.35%  (p=0.000 n=19+19)

name                      old alloc/op   new alloc/op   delta
JobQueuePushPopDone10k-8    2.56MB ± 0%    1.76MB ± 0%  -31.31%  (p=0.000 n=18+13)

name                      old allocs/op  new allocs/op  delta
JobQueuePushPopDone10k-8      23.0 ± 0%      23.0 ± 0%     ~     (all equal)

Results for BenchmarkJobQueueBump are with the fixed version, which no
longer depends on b.N for the amount of work performed. rand.Rand.Intn
is cheap at ~10ns per iteration.
@calmh
Copy link
Member

calmh commented Oct 29, 2021

Yeah deepsource can go pound sand in this case.

@calmh calmh merged commit 807a6b1 into syncthing:main Oct 29, 2021
@calmh calmh added this to the v1.18.5 milestone Nov 10, 2021
calmh added a commit to calmh/syncthing that referenced this pull request Nov 22, 2021
* main: (32 commits)
  cmd/syncthing: Implement generate as a subcommand with optional API credential setting (fixes syncthing#8021) (syncthing#8043)
  lib/model: Correct "reverting folder" log entry
  lib/model: Correct handling of fakefs cache
  gui, lib: Fix tracking deleted locally-changed on encrypted (fixes syncthing#7715) (syncthing#7726)
  lib/config: Move the bcrypt password hashing to GUIConfiguration (syncthing#8028)
  lib/syncthing: Clean up / refactor LoadOrGenerateCertificate() utility function. (syncthing#8025)
  lib/api: http.Request.BasicAuth instead of custom code (syncthing#8039)
  Normalize CLI options to always use two dashes. (syncthing#8037)
  gui: Display identicons for discovered device IDs. (syncthing#8022)
  cmd/syncthing/cli: indexDumpSize doesn't need a heap (syncthing#8024)
  lib/model: Optimize jobQueue performance and memory use (syncthing#8023)
  lib/model: Limit the number of default hashers on Android (ref syncthing#2220)
  lib/model: Set mod. time after writing trailer in shortcut (ref syncthing#7992)
  lib/protocol: Simplify codeToError, errorToCode
  lib/protocol: Eliminate nativeModel on Unix
  gui: Add direct link to Ignore Patterns from folder panel (fixes syncthing#4293) (syncthing#7993)
  gui: Translate theme names in settings (syncthing#8006)
  lib/model: Pull when a new connection is established (fixes syncthing#8012) (syncthing#8013)
  gui, man, authors: Update docs, translations, and contributors
  gui, man, authors: Update docs, translations, and contributors
  ...
calmh added a commit to calmh/syncthing that referenced this pull request Nov 22, 2021
* main: (32 commits)
  cmd/syncthing: Implement generate as a subcommand with optional API credential setting (fixes syncthing#8021) (syncthing#8043)
  lib/model: Correct "reverting folder" log entry
  lib/model: Correct handling of fakefs cache
  gui, lib: Fix tracking deleted locally-changed on encrypted (fixes syncthing#7715) (syncthing#7726)
  lib/config: Move the bcrypt password hashing to GUIConfiguration (syncthing#8028)
  lib/syncthing: Clean up / refactor LoadOrGenerateCertificate() utility function. (syncthing#8025)
  lib/api: http.Request.BasicAuth instead of custom code (syncthing#8039)
  Normalize CLI options to always use two dashes. (syncthing#8037)
  gui: Display identicons for discovered device IDs. (syncthing#8022)
  cmd/syncthing/cli: indexDumpSize doesn't need a heap (syncthing#8024)
  lib/model: Optimize jobQueue performance and memory use (syncthing#8023)
  lib/model: Limit the number of default hashers on Android (ref syncthing#2220)
  lib/model: Set mod. time after writing trailer in shortcut (ref syncthing#7992)
  lib/protocol: Simplify codeToError, errorToCode
  lib/protocol: Eliminate nativeModel on Unix
  gui: Add direct link to Ignore Patterns from folder panel (fixes syncthing#4293) (syncthing#7993)
  gui: Translate theme names in settings (syncthing#8006)
  lib/model: Pull when a new connection is established (fixes syncthing#8012) (syncthing#8013)
  gui, man, authors: Update docs, translations, and contributors
  gui, man, authors: Update docs, translations, and contributors
  ...
@st-review st-review added the frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion label Mar 10, 2023
@syncthing syncthing locked and limited conversation to collaborators Mar 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants