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

Add cached, named Visibility profiles #5074

Merged
merged 21 commits into from
Oct 10, 2024
Merged

Add cached, named Visibility profiles #5074

merged 21 commits into from
Oct 10, 2024

Conversation

rmosolgo
Copy link
Owner

@rmosolgo rmosolgo commented Aug 26, 2024

This aims to add to improvements to GraphQL-Ruby's (forthcoming) schema visibility system.

  • Ahead-of-time caching of named profiles, so that they can be reused verbatim at runtime (no calls to .visible? during execution)
  • Along with dynamic: true, which is how the current visibility system always works, calling .visible? for every schema member on every query.

Part of #5014

TODO

  • Preload named profiles when preload: true (defaults to true when Rails.env.production?)
  • Accept configured visible_in: ... or similar, for named visibility profiles
    • This is still possible, but I don't think it's pressing
  • Rename Visibility::Subset => Visibility::Profile
  • Document Visibility::Profile

@rmosolgo
Copy link
Owner Author

rmosolgo commented Oct 4, 2024

To benchmark this, I modified profile_large_result:

    schema = Class.new(ProfileLargeResult::Schema) do
      # def self.visible?(member, context)
      #   sleep 0.001
      #   super
      # end
    end

    schema2 = Class.new(schema) {
      use GraphQL::Schema::Visibility
    }
    document = ProfileLargeResult::ALL_FIELDS
    Benchmark.ips do |x|
      x.config(time: 10)
      x.report("[WARDEN] Querying for #{ProfileLargeResult::DATA.size} objects") {
        schema.execute(document: document)
      }
      x.report("[PROFILE] Querying for #{ProfileLargeResult::DATA.size} objects") {
        schema2.execute(document: document)
      }

The performance was about the same between the two (Warden a bit faster? within the margin of error.), except when a cached visibility profile was used and sleep 0.001 was present -- then Visibility::Profile was much faster.

Visibility::Profile uses a hair less memory (less than 1% difference).

@rmosolgo rmosolgo modified the milestone: 2.3.18 Oct 4, 2024
@rmosolgo rmosolgo merged commit 3ddf36b into master Oct 10, 2024
15 checks passed
@rmosolgo rmosolgo deleted the named-visibility branch October 10, 2024 19:34
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