Understanding provider lifecycle during apply

I’m very new to terraform and go as a whole, but would like to understand how providers operate during terraform operations (apply mostly).

If I have 2+ resources that use the same provider, will the provider be instantiated twice, or does it stay in memory after the first resource is executed? Is it possible to have a global var/object that stays in memory until the process is complete? Will/Can the var/object be referenced by both resources to save time?

I’d like to create a provider that requires substantial time to initialize and connect to a remote service but save the time of initializing the connection.

There is only one instance of any provider in a Terraform run. Terraform instantiates the provider and invokes its “Configuration” function so the provider can configure itself, establish connections, etc., and the function returns an object which can contain any data the provider would like to store. That object is then passed to all subsequent function invocations for that provider.

So, it’s like a global object, except it’s not: it has a specific, controlled lifetime.

Thank you for the explanation.