r/programming • • Sep 12 '22

MemLab - a framework developed by Meta for detecting JavaScript memory leaks

https://engineering.fb.com/2022/09/12/open-source/memlab/
652 Upvotes

114 comments sorted by

5

u/[deleted] Sep 13 '22 edited Sep 13 '22

How does this compare to fuite[0], is it worth migrating?

[0] https://github.com/nolanlawson/fuite

3

u/mr_sharpoblunto Sep 13 '22

There is some overlap, but MemLab is a more general purpose memory analysis framework - on top of the E2E browser leak testing it has a bunch of packages and tools for traversing and analyzing memory heaps + apis for integrating it into other pieces of infra.

132

u/issungee Sep 13 '22

Funny to hear it comes from Meta, Facebook and Messenger are consistently in the 2 worst web apps I always have open. Other contenders are Jira, Reddit & Jenkins.

159

u/light24bulbs Sep 13 '22

That's probably why they need the memory leak tool, ay?

78

u/lobut Sep 13 '22

Yeah but they've produced good tools regardless like React and GraphQL.

0

u/[deleted] Sep 13 '22

[deleted]

4

u/lonelyswe Sep 13 '22

React is amazing

26

u/bawng Sep 13 '22

React is incredibly popular. It wouldn't be if wasn't a good tool.

2

u/MintPaw Sep 13 '22

Gigachad engineering.

-11

u/ShortFuse Sep 13 '22 edited Sep 13 '22

Uh, so was jQuery. The reason why languages frameworks like Svelte and SolidJS exist is because the VDOM can get crazy expensive (specifically RAM). Both those frameworks show you don't need that overhead.

Edit: Mistakenly referred to them as languages

3

u/bawng Sep 13 '22

I'm not front-end programmer but isn't the entire point of React also the VDOM?

3

u/ShortFuse Sep 13 '22 edited Sep 13 '22

Yep, and Svelte and SolidJS (edit: also Web frameworks) ditch it.

React exists on the foundation that reading the DOM is slow and it's better to read from a virtual one. But that's a uniquely Web problem. I've never coded a language where I'm reading what I'm painting. It's always been draw calls. But React is better than whatever JS developers were doing before.

Svelte and SolidJS are more traditional (ie: mobile or desktop) where you update imperatively on change, instead of always computing tree-based diff changes and reconciling. You can code like that in React, sure, but in practice, people don't.

7

u/bawng Sep 13 '22

But the topic is web?

5

u/ShortFuse Sep 13 '22

I know you're not a frontend programmer, but Svelte and SolidJS are web frameworks and they "compete" in the same space as React.

Here's a better explanation from the Svelte devs:

https://svelte.dev/blog/virtual-dom-is-pure-overhead

3

u/bawng Sep 13 '22

Okay, fair enough, your previous comment sounded like the VDOM isn't relevant because it only applies to the web. But I misinterpreted.

→ More replies (0)

-21

u/[deleted] Sep 13 '22

Popular yes. Good? Disscutable

0

u/[deleted] Sep 13 '22

[deleted]

5

u/anengineerandacat Sep 13 '22

Not as flawed as you think, it was good enough to gain an audience; it might not be perfect but it's clearly doing something that competitors didn't.

Yes, some corporations might of bought into the hype but if success wasn't occurring around it the usage wouldn't have exploded to be a mainstream library for DOM templating.

A good tool is one that works better than the last.

0

u/[deleted] Sep 13 '22

[deleted]

4

u/anengineerandacat Sep 13 '22

I read it but didn't pick on it because your argument to use that is flawed, a VDOM library isn't the same as a language and it's underlying runtime.

It's like comparing metal with a car.

0

u/[deleted] Sep 13 '22

[deleted]

2

u/anengineerandacat Sep 13 '22

Eh, I wouldn't bet the house on it but it's a valuable metric.

Popularity exists for a variety of reasons, would React be as popular if it weren't backed by Meta? Would PHP be as prominent as it is today without WordPress?

It warrants an understanding of why it's popular, but a fair amount of times something is popular because it's genuinely good and it's fine for folks to not want to invest the time to dig further into it sometimes.

Popular languages are easier to staff around, get support for, etc.

Hence it's not fully flawed, historically popular things are good things.

Also I find it odd you think PHP is popular, it's been trending downwards for quite some time now.

13

u/ShortFuse Sep 13 '22

I have client machines who can't run basically any React sites. The memory usage is too much. Sure they're old machines, but I didn't think it was that bad.

I ported some C# applications to web and used Vanilla JS, so I'm a transplant to the community. I get downvoted to hell in the JS subreddits for trying to explain that React doesn't scale well for dense UIs because VDOM.

But the JS community is really weird about things I've never seen in any other. They care so much about lines of code and if you can write a todo list in 1500 characters rather than 1800 characters, the framework is automatically better. If it can compile down to 0.3KB instead of 0.6KB, start switching. It's pretty nauseating at times. You should be prioritizing user experience/performance for the entirety of the app usage, not if it's a couple of milliseconds better for time to First Meaningful Paint.

2

u/douglasg14b Sep 15 '22

I think it's because the JavaScript community has a significantly larger proportion of new and inexperienced developers than other languages. And it's kind of a community bubble that tends to keep them inexperienced in ways that matter.

You tend to see a lot less pragmatism when working with JavaScript projects than with others in my experience. This lack of experience or even experienced "blog driven developers" seem to get snappy rather quickly when their baby is called ugly.

When I say this as someone who has been working with web frameworks my whole career starting with jQuery, then AngularJS, then Vue and React.

If a web framework is not working for the problem that needs to be solved then it isn't working for the problem that needs to be solved.

¯\(ツ)/¯

2

u/incredible-mee Sep 13 '22

Agree !! What are some good web apps in your opinion ?

1

u/issungee Sep 14 '22

Hmm good question, maybe GitHub, Discord, Twitter, Jellyfin

0

u/[deleted] Sep 13 '22

[deleted]

2

u/CannuckInUS Sep 13 '22

Would love to hear from a Meta engineer to see if this is true.

If it's anything like my experiences, if you're going to make a big public splash about a new open source tool, you probably have also tried to do an internal campaign to get adoption.

If you don't get internal adoption, then I question the actual usefulness of the tool...

2

u/mr_sharpoblunto Sep 13 '22

It’s talked about in the article, but MemLab has been used across Meta to fix issues in React, Relay, as well as the various web apps. Not sure about other big tech - but at least at Meta you won’t get buy-in to do all the work to open source something unless it’s proven it’s usefulness internally

1

u/armhad Sep 13 '22

I am certain that they use their new tools for themselves, even if it’s in a limited scope ( experiments/few surfaces). I am at a competitor company and we certainly still incorporate new tech in portions. Certainly can’t overwrite everything, but there’s ways to incorporate it

1

u/___nate__higgers___ Sep 13 '22

Do you say this from experience? Because it hasn't been what I've seen.

153

u/[deleted] Sep 13 '22

Maybe we should ask Reddit to run this on their new site. Just saying.

70

u/agildehaus Sep 13 '22

That's no leak. NewReddit is legitimately using every last ounce of that memory.

25

u/[deleted] Sep 13 '22

Press X to doubt.

8

u/CordialPanda Sep 13 '22

It's not a memory leak, it's a memory pool that just so happens to always be closed to the public.

5

u/EagleNait Sep 13 '22

Pool's closed

2

u/splyfrede Sep 13 '22

When Reddit mining bitcoin on your phone

28

u/6769626a6f62 Sep 13 '22

Imagine using the new Reddit. I've had mine on the old this whole time, and if they ever get rid of that option, I'll install a tablet app like Relay on my PC and browse through that instead.

4

u/[deleted] Sep 13 '22

If you use iOS there's an app called Apollo. Highly recommended.

8

u/vikumwijekoon97 Sep 13 '22

Relay and apollo? Does reddit apps all have graphql library names?

6

u/Zahand Sep 13 '22

Apollo used all of my monthly data cap in two days. Fuck Apollo.

3

u/moonsun1987 Sep 13 '22

I use slide for reddit but I think on Android, at least on Lineage OS, you can set apps to only use wifi and not cellular.

3

u/mustbelong Sep 13 '22

I use Baconreader on iOS. No clue about data usage since I’ve had unlimited dataplan for years. Worth looking into, though.

2

u/___nate__higgers___ Sep 13 '22

What's better about slide?

1

u/moonsun1987 Sep 13 '22

Practically nothing. I'm just too used to it.

1

u/6769626a6f62 Sep 13 '22

I use Relay on my phone and it's the best Reddit app I've used. Though I've only tried Reddit is Fun and Relay.

3

u/mustbelong Sep 13 '22

There’s also baconreader. RIF is one of like a handful of stuff I miss since getting an iPhone.

2

u/needefsfolder Sep 13 '22

i'd even say facebook should run this on their site. you can definitely see their site using lots of ram around 30 minutes of using it.

1

u/Dgc2002 Sep 14 '22

I was in the alpha testing group for New Reddit. The amount of extremely popular feedback and criticisms they ignored amazed me. I feel like that alpha program was entirely pointless.

1

u/[deleted] Sep 13 '22

I really like reddit's web interface because it's so bad that it incentivizes not using it as much.

This is not a joke, I really only use reddit on firefox on my phone because infinite scrolling apps really do a number on my dopamine levels.

The fact that it crashes every 2-3 comment sections I visited is just an added bonus.

If they ever fix it, I'll have to make my own shitty Reddit frontend, which, right now is just Reddit.

44

u/PopoTheBadNewsBear Sep 13 '22

You know, the cumulative effect of better JS memory management in the wild is an unequivocally good thing. Kudos!

103

u/1cristidbr Sep 13 '22

This is a really valuable tool to integrate into CI/CD pipelines. Kudos to Meta for open-sourcing it

144

u/SpaceboyRoss Sep 13 '22

Idk what's up with the comment section but like JavaScript has its faults but so does every programming language and this seems like a great tool to help alleviate that.

42

u/sternold Sep 13 '22

Yeah, pretty much every major language has tools to detect memory leaks. It's actually surprising that JS doesn't really have one.

35

u/godiscominglolcoming Sep 13 '22

It does though? The DevTools in your browser as well as the node DevTools from chrome can both detect memory leaks using the memory allocation instrumentation. It even says it in the explanation that it can be used for detecting memory leaks.

JavaScript has a very rich toolset for profiling and detecting these sorts of things.

5

u/Badaluka Sep 13 '22

But that doesn't help with non browser apps. And there are a ton of them.

Every framework needs its own profiler and a generic solution would be better I think.

6

u/malfunctionneedinput Sep 13 '22

You can use the chrome dev tools to debug and profile node.js apps too. https://nodejs.org/en/docs/guides/debugging-getting-started/#inspector-clients

7

u/jl2352 Sep 13 '22

JS has quite a few. Especially for the browser.

5

u/shif Sep 13 '22

Devtools in chrome has a very rich memory analyzer, you can take heap snapshots and see a very detailed breakdown of what is using the memory.

https://developer.chrome.com/docs/devtools/memory-problems/heap-snapshots/

-3

u/cdb_11 Sep 13 '22

The problem isn't the JavaScript language, it's JavaScript developers. All of those websites used to work just fine in the past. They were already perfect, but for some reason the devs convinced themselves that they had to fix it by rewriting everything in React and whatnot. Now they've made it so painfully slow that browsing the web today is pretty much as slow for me as back in 2000s, back when the computers were just slow.

11

u/SpaceboyRoss Sep 13 '22

I don't doubt that the modern web uses too many resources but we need framework. Time is money and the less time it takes to maintain, optimize, and develop a website, the better. With your logic, you could argue that GTK and QT are bloat and that we should just be rendering directly to framebuffers.

2

u/cdb_11 Sep 13 '22

For a new product, maybe. But I'm talking about the already existing, major websites. Rewriting something that already worked just fine from scratch takes years of work, so I don't feel like the "time is money" argument really applies here. Optimization isn't true either, since everything is now undeniably slower. As for maintainability, I'd say it's maybe true for refactoring, but because of all that added complexity it's now harder to find bugs, memory leaks etc.

I think comparing HTML+CSS to writing pixels directly to the framebuffer is a stretch. I don't know what the solution to your problems is, but to me the current practices seem like a complete failure.

4

u/SpaceboyRoss Sep 13 '22

Most major websites are most likely using frameworks like React. If they aren't then there probably isn't a valid case for a rewrite. However, there's a lot of websites that still use legacy code that could perform better on the modern web using React. At my job, we've got a lot of PHP and ASP code but we're in the process of converting to Vue. We're going slow but we've noticed a significant improvement in those pages. Most people are visiting these websites on their phones and computers and if they are visiting them on a computer then it's most likely something like an XPS or a MacBook (not everyone are using those of course but it's a good example). Nobody cares about how well the websites run in most situations, they just want to use it and get whatever they need done.

1

u/cdb_11 Sep 13 '22

I don't find it surprising that a PHP interpreter might not be as fast as the JS interpreter inside your browser. But PHP and React are not the only two choices there are.

Nobody cares about how well the websites run in most situations, they just want to use it and get whatever they need done.

How do you know that? I very rarely talk about technical/programming/web stuff with normal people, but on the few occasion I did, they were annoyed by how slow it is too. It's just that because they don't understand how any of this works, so they assume it's their devices that are too slow, and that they need to waste money on a new one.

2

u/SpaceboyRoss Sep 13 '22

My mom also has the same problem but the thing is that modern GUI's require a good amount of resources. This has always been the case. And you could always tell those people that modern interfaces require more resources to perform normally because they're designed with a specific minimal hardware spec. Windows is a good example, it uses a lot of resources on old computers but that's because it's designed with modern ones in mind.

3

u/cdb_11 Sep 13 '22

You could tell those people that, but that would be a lie. There is nothing inherently more demanding about most of those "new" user interfaces. There is nothing demanding about the interface of YouTube, Gmail, Facebook, Messenger, Twitter, Medium etc., just to name a few. In fact they are pretty much the same thing they used to be, but now in a "flat" style. They are maybe programmed in with a minimal hardware spec in mind, but not designed.

2

u/SpaceboyRoss Sep 13 '22

I'm not sure how that's a lie when UI/UX tends to be the bulk of web applications. Seeing your other comments I'm just going to end it off here because it seems you just don't understand or want to listen.

1

u/cdb_11 Sep 13 '22 edited Sep 13 '22

In fact they are pretty much the same thing they used to be, but now in a "flat" style.

In the full context of the discussion this means that pretty much the same interfaces used to be fast, but are not anymore. I was pretty clear from the start on what my gripe is.

I do not mean that it's not demanding, I mean that it didn't suddenly become more demanding. It's the way people started to implement them is. And that points at either React/frameworks or the developers not knowing how to do it efficiently (and not just random "bad" developers, the developers who work on the biggest products in the world).

2

u/myringotomy Sep 13 '22

You forgot to add “kids these days” “get off my lawn” to your post.

5

u/lonelyswe Sep 13 '22

Exactly this. It's not the developers or React making the web so slow lol. In most cases its all the goddamn tracking and advertisement bullshit. If you think developers have a choice about those you are fucking delusional. There are bad JS devs but not any more than any other language. This web dev hate is ridiculous.

0

u/cdb_11 Sep 13 '22

Yes, it is React. Advertisement bullshit doesn't make Facebook Messenger's <input type=text> crawl. Reimplementing it with <div>s and rendering it with React is. This aren't just some random people who don't understand what they're doing, this is the type of shit that the company that created React does.

8

u/lonelyswe Sep 13 '22

??? What is wrong with React? You can build very performant apps with it. And the ecosystem around it is so massive, it makes development very enjoyable too. I don't see the problem.

edit: reimplementing an input with divs has nothing to do with react

0

u/cdb_11 Sep 13 '22

You've said that developers and React have nothing to do with making the web slow, and tried to blame everything on trackers, ads and bad devs. I block all trackers and advertisement, and yet all leading major websites that are written by the best JS devs in the industry are still somehow 10 times slower than what they were before they people started to rewrite everything in React.

4

u/lonelyswe Sep 13 '22

How are websites 10x slower.. Man. Whatever let's just not discuss this then. I just completely disagree with everything you are saying.

2

u/SpaceboyRoss Sep 13 '22

Yeah, this guy must be using an ancient computer or something. I've used a PinePhone Braveheart edition for quite a while and it is able to use the web, albeit a bit slow but at an acceptable speed. Most people won't have problems with the modern web.

1

u/cdb_11 Sep 13 '22

How can you accuse others of being delusional, while denying that websites got slower is beyond me. Was your first exposure to the internet 5 years ago?

-11

u/jorgp2 Sep 13 '22

Most other programming languages aren't designed with the express purpose of burning electricity.

16

u/-tired_old_man- Sep 13 '22

Funny that in their demo they are analyzing google maps... Don't they have their properties to critique, lol.

9

u/therealdan0 Sep 13 '22

console.log('Hello World');

DANGER!! DANGER!! MEMORY LEAK DETECTED!!

1

u/Efficient-Worry-6549 Feb 20 '24

Can anybody help me with analyzing authenticated pages? As per the documentation only cookie based auth is suppoerted. But for my app i need to set the localstorage

0

u/maxinstuff Sep 13 '22

It’s JavaScript thought right? So it’s not MY memory that’s leaking ;)

-43

u/X_Famine Sep 13 '22

JavaScript is the democracy of coding. The adaptivity that it has promoted for some of the brightest minds in the world offering plug-ins or packages to accomplish just about anything that you want to do speaks volumes to the language itself and those who utilize it. It is one of the more positive social experiments of our time. Anyone saying otherwise does not fully understand or is gatekeeping the creativity of others.

43

u/Desmeister Sep 13 '22

Please tell me this is copypasta

7

u/ArtemMikoyan Sep 13 '22

If it wasn't then, it is now.

10

u/StillNoNumb Sep 13 '22

JavaScript is the democracy of coding. The adaptivity that it has promoted for some of the brightest minds in the world offering plug-ins or packages to accomplish just about anything that you want to do speaks volumes to the language itself and those who utilize it. It is one of the more positive social experiments of our time. Anyone saying otherwise does not fully understand or is gatekeeping the creativity of others.

19

u/sik0fewl Sep 13 '22

Haha. What?

13

u/X_Famine Sep 13 '22

This was more meant to be a response to the haters below but I stand by its standalone value.

12

u/sik0fewl Sep 13 '22

Ok, that makes a bit more sense. It seemed like some pretty weird and out of place praise.

I think you could say the same of any popular language, too.

-3

u/mattsowa Sep 13 '22

I don't think so. It's fakr to day javascript is the only mainstream generalpurpose language with tooling such as babel that lets you preprocess almost anything in the language, however you please

-72

u/[deleted] Sep 13 '22

might be easier to just avoid programming in javascript to start with.

34

u/mattsowa Sep 13 '22

.. because?

31

u/[deleted] Sep 13 '22

Ok boomer

-10

u/bgrahambo Sep 13 '22

Ok boomer

5

u/bgrahambo Sep 13 '22

lol, always funny to see the ok boomer approval limit reached

3

u/[deleted] Sep 13 '22

I was kinda hoping for an ok boomer chain

-10

u/[deleted] Sep 13 '22

I just downvoted your comment

FAQ:

What does this mean?

The amount of karma (points) on your post and Reddit account has decreased by one.

Why did you do this?

There are several reasons I may deem a comment to be unworthy of positive or neutral karma. These include, but are not limited to:

• ⁠Rudeness towards other Redditors, • ⁠Spreading incorrect information, • ⁠Sarcasm not correctly flagged with a /s.

Am I banned from Reddit?

No - not yet. But you should refrain from making comments like this in the future. Otherwise I will be forced to issue an additional downvote, which may put your commenting and posting privileges in jeopardy.

I don't believe my comment deserved a downvote. Can you un-downvote it?

Sure, mistakes happen. But only in exceedingly rare circumstances will I undo a downvote. If you would like to issue an appeal, shoot me a private message explaining what I got wrong. I tend to respond to Reddit PMs within several minutes. Do note, however, that over 99.9% of downvote appeals are rejected, and yours is likely no exception.

How can I prevent this from happening in the future?

Accept the downvote and move on. But learn from this mistake: your behavior will not be tolerated on https://www.reddit.com/ . I will continue to issue downvotes until you improve your conduct. Remember: Reddit is privilege, not a right.

-37

u/desiInMurica Sep 13 '22

It's unfortunate that such a non-performant language became the bedrock of the Web. Maybe things will change with WASM on client side but won't hold my breath.

NodeJS is a monstrosity on the server side, but it did popularize async-await style concurrency. Now that most languages have it, makes no sense to develop server side apps in it.

https://hacks.mozilla.org/2017/02/what-makes-webassembly-fast/?

18

u/Spider_pig448 Sep 13 '22

JavaScript hasn't been slow for many years now

1

u/desiInMurica Sep 13 '22

Yes, and hence unfortunate that it ended up as defacto language for the Web

-1

u/[deleted] Sep 13 '22

[removed] — view removed comment

11

u/[deleted] Sep 13 '22

Machine code is faster than everything. Makes no sense to compare it to that - especially since most people don't directly write machine code for servers, and no one writes it for a website.

JavaScript is accessible, well-documented, and well-supported. That alone makes using it worth it, and the speed is pretty good too.

0

u/desiInMurica Sep 13 '22 edited Sep 14 '22

C/C++ run nearly as fast as assembly. So maybe they can be the baselines to compare other languages with

1

u/[deleted] Sep 13 '22

Assembly isn't machine language though, it still has to be translated so the code can actually run on the processor.

Also those benchmarks can be misleading since you can directly write assembly in C

3

u/FredFredrickson Sep 13 '22

Why does that matter? It obviously works.

3

u/hardware2win Sep 13 '22

JIT in v8 causes so much problems that I wouldnt say "it works"

1

u/desiInMurica Sep 13 '22

Memory and CPU hogs. Just because something works, doesn't mean it's performant.

0

u/jorgp2 Sep 13 '22

There's this thing called global warming.

1

u/IceSentry Sep 14 '22

Lua wasn't designed witha jit compiler in mind either. How is that even an argument against js?

-1

u/[deleted] Sep 13 '22

Perhaps if that helps you feel better about yourself

-1

u/[deleted] Sep 13 '22

Better discord plugins:

-1

u/Weak-Opening8154 Sep 14 '22

This is funny as fuck

-20

u/Apache_Sobaco Sep 13 '22

Instead of fixing the language they invent the hacks. Applause.

-26

u/[deleted] Sep 13 '22

LOL, I'm fucking laughing. JavaScript + Memory Leak Detection? Fuck, you had me at Detection.

15

u/mattsowa Sep 13 '22

Don't know shit about anything do you

-8

u/[deleted] Sep 13 '22

You wouldn't catch me trying to keep my lights on and mortgage paid from JavaScript

4

u/mattsowa Sep 13 '22

Ah, I get it now, you're insane