Skip to content

Lazy load entities when requested instead of initializing everything on load#26

Open
tomas wants to merge 31 commits into
masterfrom
lazy-loading
Open

Lazy load entities when requested instead of initializing everything on load#26
tomas wants to merge 31 commits into
masterfrom
lazy-loading

Conversation

@tomas
Copy link
Copy Markdown
Member

@tomas tomas commented Feb 2, 2023

I just realized I never submitted this PR because whatever reason. This branch is an attempt at reducing memory allocations by instantiating entities when called instead of doing as part of the response parsing process.

tomas added 23 commits April 28, 2020 18:22
…ies on requested instead of on initialization
@tomas
Copy link
Copy Markdown
Member Author

tomas commented Feb 2, 2023

This branch also includes the retry request logic from PR #14 (with tests)

@tomas
Copy link
Copy Markdown
Member Author

tomas commented Feb 2, 2023

Tests pass 100% both on Ruby 2.7.1 and 3.2.0

tomas added 4 commits May 23, 2023 17:48
Potential memory leaks:
- Entity and Relation now hold a WeakRef to the client/strategy, so
  entity graphs retained by application code (caches, sessions) no longer
  prevent the Strategy, its Faraday connection pool, and auth credentials
  from being garbage collected. A clear RuntimeError is raised if a link
  is followed after the strategy has been GC'd.
- Configuration#logger now memoises with ||= instead of ||, preventing a
  fresh Logger from being allocated on every call when no logger is set.
- Strategy no longer allocates an empty Proc.new{} when no on_new_token
  block is given; on_new_token is nil and callers use &.call.

Code improvements:
- Oauth2Strategy#retryable: remove redundant begin/end wrapper.
- Replace default Faraday::HttpCache::MemoryStore (unbounded) with
  BoundedMemoryStore, which evicts the oldest entry once the cache reaches
  500 entries, capping in-process memory growth in long-running servers.

New features:
- Client#close: nilifies the memoised Faraday connection so it can be GC'd.
- Client accepts :timeout and :open_timeout options and forwards them to
  Faraday, making request timeouts configurable without monkey-patching.
- TooManyRequestsError (HTTP 429) added to the error hierarchy so callers
  can rescue rate-limit responses distinctly from other transport
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant