Skip to content

Remove duplicate initialization of dotenv #1669

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 2 commits into from
Mar 14, 2019

Conversation

jtgeibel
Copy link
Member

While doing memory profiling, I noticed that dotenv was being
initialized each time the env helper function was called. With my
.env file in development it was (temporarily) allocating 9.7MB on
each call to the env helper.

The dotenv::var helper uses std::sync::Once and avoids this
duplicate work. I don't expect this to improve allocation patterns on
production much/any, as without a .env file, only 1.9kB is
(temporarily) allocated.

Some binaries will initialize sooner and will pick up some variables that
would not previously work from .env.

While doing memory profiling, I noticed that `dotenv` was being
initialized each time the `env` helper function was called.  With my
`.env` file in development it was (temporarily) allocating 9.7MB on
each call to the `env` helper.

The `dotenv::var` helper uses `std::sync::Once` and avoids this
duplicate work.  I don't expect this to improve allocation patterns on
production much, as without a `.env` file, only 1.9kB is
(temporarily) allocated.
At most of these call sites in library code, `dotenv` should already be
initialized.  Most of these changes are for style consistency.

Some binaries will initialize sooner and will pick some variables that
would not previously work from `.env`.
@sgrif
Copy link
Contributor

sgrif commented Mar 14, 2019

@bors: r+

@bors
Copy link
Contributor

bors commented Mar 14, 2019

📌 Commit afadfb7 has been approved by sgrif

bors added a commit that referenced this pull request Mar 14, 2019
Remove duplicate initialization of `dotenv`

While doing memory profiling, I noticed that `dotenv` was being
initialized each time the `env` helper function was called.  With my
`.env` file in development it was (temporarily) allocating 9.7MB on
each call to the `env` helper.

The `dotenv::var` helper uses `std::sync::Once` and avoids this
duplicate work.  I don't expect this to improve allocation patterns on
production much/any, as without a `.env` file, only 1.9kB is
(temporarily) allocated.

Some binaries will initialize sooner and will pick up some variables that
would not previously work from `.env`.
@bors
Copy link
Contributor

bors commented Mar 14, 2019

⌛ Testing commit afadfb7 with merge 1b42e4c...

@bors
Copy link
Contributor

bors commented Mar 14, 2019

☀️ Test successful - checks-travis
Approved by: sgrif
Pushing 1b42e4c to master...

@bors bors merged commit afadfb7 into rust-lang:master Mar 14, 2019
@jtgeibel jtgeibel deleted the remove-duplicate-dotenv-inits branch July 14, 2019 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants