Skip to content

Cache proto objects #2755

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

Merged
merged 1 commit into from
Nov 28, 2017
Merged

Conversation

kolodny
Copy link
Contributor

@kolodny kolodny commented Nov 23, 2017

Creating proto objects are incredibly expensive due to the usage of loadProtoFile_ which eventually calls readFileSync.

This PR keeps track of a cache to minimize those calls. Try the following before and after the change:

const BigTable = require('@google-cloud/bigtable');

for (let i = 0; i < 20; i++) {
  console.time(i);
  const bigtable = BigTable();
  console.timeEnd(i);
}

Before:

0: 61.598ms
1: 42.123ms
2: 35.100ms
3: 47.477ms
4: 34.963ms
5: 45.671ms
6: 23.578ms
7: 36.888ms
8: 39.864ms
9: 27.422ms
10: 24.460ms
11: 38.407ms
12: 33.231ms
13: 33.515ms
14: 31.255ms
15: 38.172ms
16: 23.016ms
17: 33.301ms
18: 30.991ms
19: 43.421ms

After:

0: 48.167ms
1: 0.276ms
2: 0.144ms
3: 0.141ms
4: 0.089ms
5: 0.133ms
6: 0.089ms
7: 0.077ms
8: 0.103ms
9: 0.115ms
10: 0.129ms
11: 0.086ms
12: 0.077ms
13: 0.119ms
14: 0.093ms
15: 0.077ms
16: 0.125ms
17: 0.127ms
18: 0.117ms
19: 0.206ms

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Nov 23, 2017
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling a6b7e2b on kolodny:cache-proto-objects into b8a00b2 on GoogleCloudPlatform:master.

@stephenplusplus
Copy link
Contributor

stephenplusplus commented Nov 28, 2017

LGTM! Thanks, @kolodny!

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

Successfully merging this pull request may close these issues.

4 participants