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

Etag and refresh optimizations #3346

Closed

Commits on Nov 24, 2019

  1. Improve performance of etag calculation for /

    - Only compute etag once (rather than twice) per request.
    - Only stat files once per request.
      - Avoid calling `isdir` or `isfile` in `collect_files`.
      - Leave it to `compute_lastmodified` to stat files, which tells us if
      the path exists, if it is a file, and it's last modified.
      - Reduces the number of stat systemcalls by 50%.
    justfalter committed Nov 24, 2019
    Copy the full SHA
    42d3465 View commit details
    Browse the repository at this point in the history
  2. Memoize settings hashes to speed up cache refresh

    Memoize `settings.config_hash` and `settings.effective_hash`. The
    hashes will only be calculated on the first call to the respective
    functions. These memoized values are invalidated when the settings
    object becomes dirty, or the settings are loaded from the config file.
    
    Reason for change: During a refresh of the root route (/), the hash of
    `settings.effective.yaml` is calculated 5 times. Each call lead to a
    large configuration object to be serialized to a YAML string, which would
    then be hashed. As it turns out, serializing to YAML is expensive.
    
    Note: while I do not see `settings.config_hash` hit during a refresh,
    but making a change to it was easy and appropriate. It's possible that
    other areas of the application may see some benefit.
    
    Performance (on my 2016 Macbook Pro:
    - building of initial cache on startup:
      - before: ~3.4s
      - after:  ~2.9s
    - loading `http://octoprint/?_refresh=1`
      - before: ~1100ms
      - after:  ~200ms
    justfalter committed Nov 24, 2019
    Copy the full SHA
    fe575ae View commit details
    Browse the repository at this point in the history