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

Avoid expensive refreshable creation in a potentially hot path #2274

Merged
merged 3 commits into from
May 6, 2024

Conversation

carterkozak
Copy link
Contributor

==COMMIT_MSG==
Avoid expensive refreshable creation in a potentially hot path
==COMMIT_MSG==

@changelog-app
Copy link

changelog-app bot commented May 6, 2024

Generate changelog in changelog/@unreleased

What do the change types mean?
  • feature: A new feature of the service.
  • improvement: An incremental improvement in the functionality or operation of the service.
  • fix: Remedies the incorrect behaviour of a component of the service in a backwards-compatible way.
  • break: Has the potential to break consumers of this service's API, inclusive of both Palantir services
    and external consumers of the service's API (e.g. customer-written software or integrations).
  • deprecation: Advertises the intention to remove service functionality without any change to the
    operation of the service itself.
  • manualTask: Requires the possibility of manual intervention (running a script, eyeballing configuration,
    performing database surgery, ...) at the time of upgrade for it to succeed.
  • migration: A fully automatic upgrade migration task with no engineer input required.

Note: only one type should be chosen.

How are new versions calculated?
  • ❗The break and manual task changelog types will result in a major release!
  • 🐛 The fix changelog type will result in a minor release in most cases, and a patch release version for patch branches. This behaviour is configurable in autorelease.
  • ✨ All others will result in a minor version release.

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Avoid expensive refreshable creation in a potentially hot path

Check the box to generate changelog(s)

  • Generate changelog entry

return cf.uris().map(targets -> targets.size() == 1)::get;
// Avoid using refreshable here, as this can be called very frequently, and
// refreshable.map can be expensive.
return () -> cf.uris().get().size() == 1;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to create a refreshable.map target for each endpoint. We could extract a refreshable.map to a higher layer, but this is probably simpler (list.size is just a field read)

UnsafeArg.of("targets", targetUris),
SafeArg.of("numTargets", targetUris.size()));
ImmutableList<LimitedChannel> targetChannels = createHostChannels(cf, targetUris);
return NodeSelectionStrategyChannel.create(cf, targetChannels);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

combined two refreshable.map calls since we're really doing one thing here, should be easier to follow

}

/* Abstracts away DialogueChannel so that we can handle no-service/no-uri case in #getInternalDialogueChannel. */
private interface InternalDialogueChannel extends Channel {
private interface InternalDialogueChannel extends Channel, EndpointChannelFactory {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the most important change, we have a lot of code which attempts to cast Channel to EndpointChannelFactory and use endpoint(endpoint) on the result, failing that it will call the Channel.execute(Endpoint,Request) method, which internally delegates to the preferred endpoint method. Unfortunately that ends up re-computing a great deal of info on each invocation.

This cruft exists to avoid breaking dialogue API :-/

bjlaub
bjlaub previously approved these changes May 6, 2024
@policy-bot policy-bot bot dismissed bjlaub’s stale review May 6, 2024 19:02

Invalidated by push of b68f82a

@bjlaub
Copy link
Contributor

bjlaub commented May 6, 2024

👍

@bulldozer-bot bulldozer-bot bot merged commit 701667f into develop May 6, 2024
6 checks passed
@bulldozer-bot bulldozer-bot bot deleted the ckozak/refreshables branch May 6, 2024 19:05
@svc-autorelease
Copy link
Collaborator

Released 3.131.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants