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

Pre-cache the services by name dictionary. #931

Merged
merged 1 commit into from
Aug 10, 2020

Conversation

Lukasa
Copy link
Collaborator

@Lukasa Lukasa commented Aug 10, 2020

Motivation:

Currently whenever we construct the GRPCServerRequestRoutingHandler we
need to give it a dictionary of services by name. This is currently done
via a computed property. The result of that is that we compute this
dictionary on the fly every time we receive a new RPC, which is not
exactly the most efficient usage model.

Instead, we should just calculate this ahead of time and save the thing
we actually want, which is the Dictionary. As this data structure is
read vastly more often than it is written, this ends up being a
minor performance win in basically all server applications.

A note: technically this is very subtly breaking as it no longer
guarantees that the Array containing the Services will be in the same
order when you read it as when you set it. I think this is acceptable:
the odds that anyone will rely on this behaviour is low. If we'd minted
1.0.0 I wouldn't take the risk, but right now I think it's ok to take it
and just document our way out of it.

Modifications:

  • Replaced stored property storing services with one storing services by
    name.

Results:

Minor performance improvement.

Motivation:

Currently whenever we construct the GRPCServerRequestRoutingHandler we
need to give it a dictionary of services by name. This is currently done
via a computed property. The result of that is that we compute this
dictionary on the fly every time we receive a new RPC, which is not
exactly the most efficient usage model.

Instead, we should just calculate this ahead of time and save the thing
we actually want, which is the Dictionary. As this data structure is
read vastly more often than it is written, this ends up being a
minor performance win in basically all server applications.

A note: technically this is _very_ subtly breaking as it no longer
guarantees that the Array containing the Services will be in the same
order when you read it as when you set it. I think this is acceptable:
the odds that anyone will rely on this behaviour is low. If we'd minted
1.0.0 I wouldn't take the risk, but right now I think it's ok to take it
and just document our way out of it.

Modifications:

- Replaced stored property storing services with one storing services by
  name.

Results:

Minor performance improvement.
@Lukasa Lukasa requested a review from glbrntt August 10, 2020 13:57
@glbrntt glbrntt added the 🔨 semver/patch No public API change. label Aug 10, 2020
@glbrntt glbrntt merged commit 36e8085 into grpc:main Aug 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants