Compare commits

...

3 commits

Author SHA1 Message Date
evanboyle 235f60fa02 use full provider string as hash key 2021-03-29 18:27:21 -07:00
evanboyle adc8b85e2c changelog 2021-03-29 15:47:16 -07:00
evanboyle 0628098b5c cache serialized dynamic providers in nodejs 2021-03-29 15:35:12 -07:00
3 changed files with 26 additions and 2 deletions

View file

@ -3,6 +3,9 @@
### Improvements
- [sdk/nodejs] Improve performance of dynamic providers by caching serlialized/deserialized providers.
[#6646](https://github.com/pulumi/pulumi/pull/6646)
- [cli] Support full fidelity YAML round-tripping
- Strip Byte-order Mark (BOM) from YAML configs during load. - [#6636](https://github.com/pulumi/pulumi/pull/6636)
- Swap out YAML parser library - [#6642](https://github.com/pulumi/pulumi/pull/6642)

View file

@ -57,9 +57,20 @@ process.on("exit", (code: number) => {
}
});
const providerCache: { [key: string]: dynamic.ResourceProvider} = {};
function getProvider(props: any): dynamic.ResourceProvider {
const providerString = props[providerKey];
let provider: any;
if(providerCache[providerString]) {
provider = providerCache[providerString];
} else {
provider = requireFromString(props[providerKey]).handler();
providerCache[providerString] = provider;
}
// TODO[pulumi/pulumi#414]: investigate replacing requireFromString with eval
return requireFromString(props[providerKey]).handler();
return provider
}
// Each of the *RPC functions below implements a single method of the resource provider gRPC interface. The CRUD

View file

@ -165,6 +165,8 @@ function serializeProvider(provider: ResourceProvider): Promise<string> {
return runtime.serializeFunction(() => provider).then(sf => sf.text);
}
const providerCache = new Map<ResourceProvider, Promise<string>>();
/**
* Resource represents a Pulumi Resource that incorporates an inline implementation of the Resource's CRUD operations.
*/
@ -184,7 +186,15 @@ export abstract class Resource extends resource.CustomResource {
if (props[providerKey]) {
throw new Error("A dynamic resource must not define the __provider key");
}
props[providerKey] = serializeProvider(provider);
let serializedProvider: Promise<string>;
if (providerCache.has(provider)) {
serializedProvider = providerCache.get(provider)!;
} else {
serializedProvider = serializeProvider(provider);
providerCache.set(provider, serializedProvider);
}
props[providerKey] = serializedProvider;
super("pulumi-nodejs:dynamic:Resource", name, props, opts);
}