Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Fix Some Leaks #2128

Merged
merged 5 commits into from
Nov 11, 2017
Merged

Fix Some Leaks #2128

merged 5 commits into from
Nov 11, 2017

Conversation

stefanpenner
Copy link
Contributor

@stefanpenner stefanpenner commented Oct 31, 2017

[FIXES #2098]

We noticed our ember-cli builds for linkedin.com were consuming ~10gb of memory, after some investigation node-sass (via eyeglass) was identified as the primary culprit. With this PR, memory usage dropped by from ~10gb -> ~1gb (saving about 9gb of ram)

NOTE: This does not fix all the leaks, more PR's to come

Fixes so far:

  • create_string must be paired with a free (this catches a few of the easy ones)
    • number constructor's unit (sass_make_number copies the unit)
    • string constructor's value (sass_make_string also copies the string)
    • Bindings ExtractOptions function signature (sass_make_function copies the signature)
  • SassTypes::Value are now subclasses of Nan::ObjectWrap, and we utilize its machinery for memory management. This ensures our wrapper objects no longer leak Nan::ObjectWrap docs

Tests:

  • add some isolated memory-test examples, which are handy to diagnose/fix memory leaks
  • back-port tests for sass.types.*
  • in sass-eyeglass/eyeglass
  • in the build system for Linkedin.com

Notes:

I realize this PR is quite large, the only drastic change was utilizing Nan::ObjectWrap memory management machinery. The rest is a mixture of tests, and cleanup to simplify the memory issues.

I look forward to you code reviews!

@stefanpenner
Copy link
Contributor Author

Looks like i got some eslint errors, will circle back shortly and fix.

@saper
Copy link
Member

saper commented Oct 31, 2017

Looks good to me, only need to wade through white space changes....

@stefanpenner
Copy link
Contributor Author

only need to wade through white space changes....

sorry about that, I can likely split the whitespace stuff into a separate commit tonight if you need.

@kyleshay
Copy link

FYI the w=1 query param hides whitespace changes:
https://github.com/sass/node-sass/pull/2128/files?w=1

@xzyfer
Copy link
Contributor

xzyfer commented Nov 1, 2017

Thanks @stefanpenner, this all looks great to me. I'll investigate what's up with CI, it failure looks to be transient.

@stefanpenner
Copy link
Contributor Author

stefanpenner commented Nov 1, 2017

@xzyfer / @saper thanks.

If you got some time to chat let me know. I have some ideas that might improve this bridge code some more, but would be a larger change, and I wouldn’t want to go down that path unless it sounds semi ok to you folks.

@stefanpenner
Copy link
Contributor Author

@xzyfer I appears the failure is on node 9, its possible that #2130 may address? Will investigate locally

@xzyfer
Copy link
Contributor

xzyfer commented Nov 2, 2017

I see. We test against latest which has since been updates to Node 9 before we were ready.

We're definitely open to talking more about the binding code. Most of it predates myself, and possibly all the active currently team. You can join our Slack to chat (timezones permitting).

@stefanpenner stefanpenner mentioned this pull request Nov 2, 2017
* boolean
* function-bridge
* map
* string
Nan::ObjectWrap Docs: https://github.com/nodejs/nan/blob/master/doc/object_wrappers.md#api_nan_object_wrap

Prior to this, all wrapper Objects would never be deleted, allowing memory to grow unbounded.

Example:
The following, would leak WrapperObjects, and never

```
while (true) {
  new sass.types.String(‘I LEAK’);
}
```
@stefanpenner
Copy link
Contributor Author

stefanpenner commented Nov 2, 2017

rebased \w node 9 appveyor fix... let's see if CI agrees 🤞

@stefanpenner
Copy link
Contributor Author

@xzyfer if this is green, do you think we can get a release out soon? If I can help at all with that, please don't hesitate to reach out.

@xzyfer
Copy link
Contributor

xzyfer commented Nov 2, 2017 via email

@stefanpenner
Copy link
Contributor Author

stefanpenner commented Nov 2, 2017

@xzyfer can you guestimate an ETA (1 day, after the weekend, 1 week, 1 month etc).

I have to coordinate some stuff on my end of the world if this is a ways out yet. Knowing the above would help me plan :)

🍻

@xzyfer
Copy link
Contributor

xzyfer commented Nov 2, 2017 via email

@stefanpenner
Copy link
Contributor Author

@xzyfer awesome, thanks for the heads-up!

@stefanpenner
Copy link
Contributor Author

its green!

Sass_Value* x = static_cast<Sass_Value*>(value);
SassTypes::Value* y = SassTypes::Factory::create(x);

argv.push_back(y->get_js_object());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this only cosmetic change or is there some deeper reason behind it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cosmetic

@saper
Copy link
Member

saper commented Nov 9, 2017

Merged with 734c7c8, thank you very much!

@saper saper closed this Nov 9, 2017
@nschonni
Copy link
Contributor

nschonni commented Nov 9, 2017

@saper I think we should revert this (temporarily) and land #2147 as a 4.6.1. Including this means we need to rebuild every binary

@stefanpenner
Copy link
Contributor Author

stefanpenner commented Nov 9, 2017

Merged with 734c7c8, thank you very much!

@saper I will likely have some more leak fixes soonish (maybe a week), but these address the largest of the leaks I've run into. It took our build from 10gb ram -> 1.3gb ram.

@xzyfer
Copy link
Contributor

xzyfer commented Nov 9, 2017

I agree with @nschonni. I'm also away atm so we can't build the new binaries.

@saper saper reopened this Nov 9, 2017
@saper
Copy link
Member

saper commented Nov 9, 2017

Temporarily reopened

@saper
Copy link
Member

saper commented Nov 9, 2017

Shall we cut v4.6.1 now with #2147 ?

@xzyfer
Copy link
Contributor

xzyfer commented Nov 9, 2017

I have some questions about #2147. I'm not sure it's ready.

@evanfuture
Copy link
Contributor

evanfuture commented Nov 10, 2017

Sorry for the error on my part, but I think #2147 is good to go now. (also sorry, I'm in Europe, so we aren't in front of our screens at the same time!)

@saper
Copy link
Member

saper commented Nov 10, 2017

Some of us are in Europe, too :) thanks

@stefanpenner
Copy link
Contributor Author

Just sharing some positive test results:

We have been running with ^ for a few days now, Thousands of builds, across various node versions and MacOS Sierra, RHEL 6, RHEL 7. No issues and just (as predicted) a nice drop in RAM usage. We have seen as much as 22gb reduction in memory usage...

@xzyfer
Copy link
Contributor

xzyfer commented Nov 11, 2017 via email

@xzyfer xzyfer merged commit e3ca075 into sass:master Nov 11, 2017
@xzyfer
Copy link
Contributor

xzyfer commented Nov 11, 2017

Since we need to rebuild binaries for this I'm also going to bump libsass to that latest 3.5 release to fix a couple other outstanding issues.

@saper
Copy link
Member

saper commented Nov 11, 2017

Great. TIL: using git commit ----cleanup=whitespace to add release notes in Markdown to the release commit - this will be picked up by @appveyor and added to the release tag on GitHub.

@xzyfer
Copy link
Contributor

xzyfer commented Nov 12, 2017 via email

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

Successfully merging this pull request may close these issues.

custom function leak
6 participants