Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Hi all, Discord engineer here! If anyone has any questions about the post or our experience using React/React Native the team would be happy to answer them!


Why does Discord need 2G RAM if you don't restart it regularly?

In your defense, it's a cancer that all "modern" apps done in javascript suffer from, but still, why?


Is Discord really using 2GB of RAM for you? Can you clarify what you mean by regularly? Discord (including all of its helper processes) is only using 190 MB of RAM for me at the moment.


The screenshot below was a particularly bad day... but Discord, Skype and Slack (all javascript "applications") compete continously for eating more ram than my actual work stuff.

https://imgur.com/a/NrNTDop

Edit: for those who don't want to click, it's a screnshot of the os x activity monitor showing the worst memory consumption, in order: Discord Helper 1.98 Gb, kernel_task 1.67 Gb, Skype Helper 1.58 Gb, Slack 1.20 Gb :)


This is getting really, really old.

Modern RAM doesn't work the way people who complain about Slack/et al think it does. The operating system will cull it from other places when it needs it; even a native Cocoa app will not dump memory you're done with until the system decides it needs it for something else, because on the off-chance your app ends up needing it again, it's already allocated. "purge" exists for a reason.

It's like when you pull up a StackOverflow answer for "how can I judge how much memory usage my process has?", and the top voted answer is some bash script to determine peak ps, when every other answer tries to explain that that's only one measure of memory and isn't even totally accurate.

Furthermore, that nice feature of most modern apps where you're scrolling up rapidly and an image is nice and ready to present? Images are big, especially when we all use retina displays. They take up memory. There was a blog post that went on HN a few months ago but didn't seem to make the front page, wherein the author determined that forcing Electron to dump image cache junk lowers the memory usage substantially.

Could Electron & co do better? For sure. Loading an entire browser for a UI does kind of suck. But stop acting like all the stuff that the browser does for you _for free_ is or should be zero-cost.

End rant, I guess.


If the memory consumption of a process grows from 200 M (which is about what the chat apps use when freshly started) to 2 Gb, something is rotten by any metric. The system was responding slowly when I made that screenshot because it started using swap. Which got instafreed the moment i restarted the memory hogs.

If i don't restart the machine for a year, is the pretty chat app going to keep in ram, uncompressed, all the cat pictures that people posted in the last 12 months then? Do you think that's sane?


> If the memory consumption of a process grows from 200 M (which is about what the chat apps use when freshly started) to 2 Gb, something is rotten by any metric.

That is just not how memory works anymore, at least not how the OS reports it to you.

> The system was responding slowly when I made that screenshot because it started using swap.

How did you determine this? If you're looking at swap usage in activity monitor, this is also not an accurate metric. I'm sitting here with 14GB used, 18GB free and 2GB of swap usage. Using swap does _not_ mean you are out of ram, it just doesn't work like that.

Is the memory pressure graph in activity monitor yellow or red? If not, which is likely the case, you don't have memory issues. You don't need more memory and it doesn't matter how much memory your applications are using.


I don't know the details of "how memory works anymore", but I do know that on my Fedora 27 laptop, everything stays nice and snappy, with under 200mb swap used, as reported by the system monitor...

...until I hit 8 gb of ram (the amount installed on my machine). The second that happens, the entire OS grinds to a halt. It starts with 5-10 seconds to change focus, and can go as high as 5 minutes if I don't do something about it. My best option for dealing with it is usually opening a new console (Ctrl-Alt-F3) and killing Android studio or the gradle daemon (the most common culprits). If I'm able and patient enough to open system monitor at this point, I can see that my swap usage has increased dramatically.

Again, I can't speak to "how memory works", but I am absolutely the expert on how my computer performs, as described above.


I've had similar experiences. Often Firefox is what's eating all the RAM, and I'm viewing it with htop. I've had cases where the freeze is indefinite and I had to hold in the power button. Couldn't change to another TTY or even ssh into the machine. When people say SWAP isn't needed, I just get mad. I've delayed these halts a bit by having some SWAP available. If I ever get slowed mouse movement, I panic and quickly check RAM usage and determine what has to be killed or restarted. I don't really understand why people pretend this doesn't happen and that unused RAM is always wasted RAM.


> ...until I hit 8 gb of ram (the amount installed on my machine).

I'm assuming you mean 8GB of ram 'used', by some metric of 'used'. What tends to confuse the hell out of people is what 'used' means. It varies by how it's measured, what OS you are using and how that OS is configured. I haven't a clue how Fedora 27 is configured nor how you are determining 'used' RAM, so my comment may well not apply to your use case.


I have exactly the same experience with Fedora.

And frankly, it seems to me like the issue is the OS being unoptimized or apps being leaky on it, because my Windows 7 machine with worse specs almost never has such issues, under any kind of similar load (and exactly the same apps).


Quit it. It was 32 Gb used (i.e. all of it, maybe 1-2 G left for cache) plus 5-6 G of swap.

I don't know how your OS X works, but mine tends to not go into swap before running out of ram. It does not come out of swap when ram is freed indeed, but when you freshly boot it it will stay at swap used: 0 bytes until someone posts too many cat pictures in Slack or Discord.

Or until i forget how many VMs I opened, but that's work and actually useful.

Edit: I can't reply to your reply because HN doesn't like so many indents. I also don't want to continue a flame war about observed behaviour vs the theory of shared libraries and memory mapped files etc so I'll stop here.


What was the state of memory pressure? It's really the only thing that matters.


RAM is fast, disk is slow, network is really slow. Your operating system optimises for performance. Minimising RAM usage is bad for performance, because empty RAM is wasted RAM.

If your RAM is full, there is a probability that something will need to be read from disk. If your RAM is empty, there is a certainty that something will need to be read from disk or from the network. A probability of a slow operation is preferable to the certainty of a slow operation. Something in RAM is preferable to nothing in RAM.

The pretty chat app will not keep all of your cat pictures in RAM indefinitely, because the OS won't let it. If something else needs that RAM, then the cat pictures will be paged to disk. The OS is incredibly good at figuring out what belongs in RAM and what belongs on disk at any given moment.


> RAM is fast, disk is slow, network is really slow.

(all speeds are read time) RAM speed: 35 GB/s Disk speed: 3.2 GB/s Network speed: 0.87 GB/s

While you aren't wrong, I have no problem loading cat pictures at network speed instead of ram speed.

I think the real issue here is network consumption is expensive. It's better if you store all your cat pictures for as long as possible. People would complain in discord generated gigabits of temporary disk files, but RAM usage can always be freed if the OS demands it.


Paging to disk makes it act much slower than simply releasing the memory when that cat has been off the screen for a moment. It is not a good solution.


It's really just kind of OK at doing that and machines running lots of apps like that tend to perform badly.

You probably run a machine with above average ram and ship apps with below average performance for lack of this understanding.


The 2GB in his screenshot means that 2GB has been malloc'd and used. RAM reported as in use by an application is not being used by the OS to cache things.

RAM that's reported as "free" by OS X's activity monitor/windows' task manager is used for disk caching.

RAM reported as in use by an application is in use by that application. It could be using some sort of internal cache, but it does not give that memory up to other apps under memory pressure except by the OS swapping it out which gets very slow.


If I understand correctly this is true for the memory allocated by the os to cache files which makes intuitive sense as a file can just be read from disk if needed.

Its not clear to me how it would apply to other memory how does the os communicate to Firefox that it needs to clear out some memory for Chrome save by moving less used pages to swap with the probable high cost, of moving it back later. Further while some intelligence may be exercised insofar as which pages to swap it won't be made with the benefit of the app deciding which chunks of data to keep closer at hand.

Modern memory works the same way it always has and the best performance has always been maintained by staying within the boundaries of available ram and not needing to swap much.

When most computers have no more than 8gb of ram and consumer machines are likely to have 4 its kind of silly for a chat app to use 1-2 sillier yet to claim that the os will fix the matter.


Were you thinking of this post? http://seenaburns.com/debugging-electron-memory-usage/ Curious if other people have more on it


Ah, missed the responses on this thread due to some work stuff - this looks like it, yeah! Thanks for digging it up. :)



OS cache actually gets released when there's memory pressure, which is very different from a program eating memory.


When you calculate the sum of the so-called "memory consumption" of all processes, you generally end up with a number ridiculously above your the amount of physical memory installed on your box.

The only reliable way to learn the memory consumption of a process is to somehow make sure other processes don't allocate/deallocate memory, kill the process in question and watch the difference in global memory consumption.


On my windows 7 I just calculated sum for all processes and I got exactly the same number as displayed for RAM used on Performance tab.

For anyone interested to repeat it fast, run this in powershell:

Get-Process | Format-Table WorkingSet > c:\data.txt

Import contents in excel and sum all cells.


The post says, "it’s roughly 1.5s startup delay to load a 15mb bundle on an iPhone X."

I've seen startup latency much slower than that on my iPhone SE. In the best case, the application takes about six seconds to cold boot when I tap on a notification. Sometimes it's closer to fifteen or twenty seconds if the app sits on the "connecting" screen for a while. It's difficult to understate how much slower the app feels than everything else on my phone.


Hey, blog author here! The startup delay is the extra initialization time that React Native needs. Translating into our discord iOS app, it is the duration of the screen with spinning mascot and quote rather than the entire duration fully connect to our gateway socket.
 In our test case, its about 4s delay on iPhone SE.


Meanwhile, we keep working towards to improving our user experience on all the devices especially the lower-end ones (I personally use iPhone 6 as my go-to test device). For instance, we will add caching very soon to shorten the interaction waiting. Hopefully you will enjoy more using Discord on your SE then :)


The X is the most expensive iPhone you can buy right now, and the SE is the cheapest. Too bad engineers practically always have the top-end models, so they don't really have to dogfood the everyday pain of using the slower devices.


Actually I don't own an iPhone X :P Our core user base tends to use 6 and above (approx 2 generations behind) and we dogfood regularly with a huge group of beta testers (thousands) with a huge range of hardware. We try our best to make sure the average use case is considered.


Considering the average is good but it still pushes the performance treadmill forward.

If we had some magical way to make the dev treadmill run slower than the user treadmill, we'd see better architectures in many cases. In that alternate world it would be easy to precompile the javascript and load 20 times faster.


As an iOS dev, I use my personal phone (iPhone X) for the bulk of my dev/test cycle but also keep around an old-ish iPod Touch running the previous version of iOS that I dev/test on periodically as well. If something doesn’t perform adequately on the Touch, I tweak on it until it does.

iOS users tend to run newer devices generally which might lead some devs to feel that this extra optimization isn’t worth the time it takes, but I disagree because it doesn’t benefit only users with older devices – it’ll make your app run better on newer devices too and make it that much more unlikely that your app gets killed or causes the OS to kill other apps in multitasking scenarios (iOS kills resource hogs much more readily). In short, everybody benefits.

With this same thought process, I plan to pick up one of the 120hz iPad Pro models to test on soon. It’s one of the most powerful iOS devices available, but driving 120FPS isn’t easy and given how many apps fail to hit the target of 60FPS on similar hardware I’d bet that a huge number, perhaps even most, don’t come anywhere close to running at 120FPS even with the extra horsepower.


That creates opportunities for other developers to build a better product.


That kind of optimization is happening much more on Android than on iOS, the install base of low end devices is much, much larger.


Slower storage and slower CPU on the SE? Maybe that is a factor, I'm not quite sure.


I don't have a question, I just want to say that I really have enjoyed using Discord. It's been a pleasure. And I'm traditionally an IRC die-hard.

Thanks for all of your work.


Thanks!

And thank you for helping make Rust awesome.


Thank you! :)


* I'm curious as to what performance degradation you've seen on Android?

* Have you evaluated cross-platform "native-ish" alternatives? (Nativescript, Flutter, etc.)

* What does the "lack of 64-bit support" mean for Android?


* Mentioned in another comment, but generally the performance of animations was poor with mixed in with any other kind of UI rendering - particularly on older phones (when we prototyped iOS we really only focused on the latest two generations of iPhones).

* This can be worked around by deferring work when doing transitions/animations based on user interaction but at the time we only had a single Android Engineer (myself) and I felt it would be an overly large hurdle to cross. The team is however still interested in trying again some point in the future now that we have more time for it.

* The minimum version we support is API level 16 which is quite old and we may eventually bump that to 17.

* We have not evaluated any native-ish alternatives mostly due to bandwidth but also because the goal is to re-use our stores/business logic from the desktop/ios clients so we can move faster.

* On 64-bit support https://github.com/facebook/react-native/issues/2814 it ca be worked around without much consequence but is a consideration as ones application grows in complexity and dependencies.


There's a linked issue in React Native regarding 64-bit: https://github.com/facebook/react-native/issues/2814. In short, you can't use 64-bit dependencies.


This is not related to the post but I have an honest question. I use nitro(and absolutely love it) and I'm constantly getting inquiries about how I use blobs. There are literally 5 accounts I would happily gift a nitro subscription to but dont have the option. When is discord going to allow people to gift nitro to other accounts. It's a huge potential revenue stream and something I would happily engage in if I had the chance to. Thank you for your work. I love discord.


It's been discussed a lot internally - I would love to gift Nitro to folks myself ala Reddit Gold :)

I believe it's something we may eventually take on - just not currently planned - there are a lot of ways we could make the nitro experience better.


Awesome post, and it's really impressive what you have managed to build with such a small team! Could you go into more detail regarding your problems with Android? Poor performance of touch events seems like the kind of thing that would make RN/Android unsuitable for most teams, so why does it have such widespread adoption?

Any other insights would be great, as I'm planning to start converting my web app to RN in the next months and didn't know Android would be a problem.


Sure,

When we originally got it running on Android (without the chat view since that component is native in the iOS app) we found that it performed quite poorly due to most of our pages being heavy on data and UI - as well as being very reactive (a typical discord server might have hundreds of permissions, messages and users all changing/updating in real time). React Native is single threaded and while iPhone’s have great single threaded performance, Android phones are more reliant on multiple cores and RN as I understand it mostly can’t take advantage of that.

On higher end Android phones the performance was actually fairly acceptable out of the box, but our user base has a lot of gamers who are running very old Android phones from many years ago - and in those situations the lag was unacceptable. For iOS, most users tend to only last one or two hardware generations behind.

Additionally, at the time React Native for Android had just been released and there were a whole host of other issues at the time - bugs and lack of Android specific components like the Navigator (which have since mostly been ironed out).

Today I think it is possible to build a fast React Native Android application and I would recommend someone starting from scratch do so :). However now the challenge is that we have an existing Native Android app so our users already have a baseline expectation of feature parity and performance. If we switch over we must meet or exceed that bar.


As a user of the iOS app it used to have some admittedly frustrating problems, but pretty much every complaint I had previously has since been fixed, huge kudos on the progress you've made!

The only thing left that really bugs me is the fact that you can't paste images from the clipboard into the message field. It's made me change my entire workflow, from copying images to saving them.

Sorry to use this as a soapbox for my pet issue, but I saw the opportunity :P


We are actually starting work on allowing pasting images from the clipboard this week :D

So stay tuned!

Thanks for the kind words, the team really appreciates it.


This makes me so happy, thank you! :D


Thanks a lot for the writeup. We've been using react native for a while now at our org and while we aren't native developers, we are getting along really well.

One question that popped up in my while reading the article was would you consider doing the android app in react native if you had to start now ? Or do you still feel it lacks the coherency it has with iOS.


Based on our experience yes I would certainly consider doing the Android side in React Native starting today.

While the performance footprint is mostly the same - the ecosystem and feature set around it has improved a ton to the point where I believe you could get it 90% there very quickly.

One of my friends has a small startup and they went full React Native as a team of two and they describe the Android side as "free" as in they really just focus on iOS and it 90% of the time it also works fine on Android (they care less about older devices at the moment so they don't spend time optimizing for those).

Android inherently will always have challenges due to the vast number of devices and hardware/performance problems but going native isn't a silver bullet either and doesn't shield you from the challenges entirely - it's just a familiar form of pain ;P


Why, starting I think about 30 or so days ago, does Discord start using insane amounts of CPU time when it is started on a system that doesn't have network connectivity? On a Surface 3 Pro, A newer laptop, and a desktop system I have seen this happen. It will just use 20-40% of available CPU unit networking is restored.


Not related to React/React Native, but I was wondering if there was a way to show a users online/idle/offline status through an API call or if there are plans too.

I've been using Discord's OAuth and that's been nice, but I what I'd really like is to display that status on my site.


Why on earth don't you have a separate button for emoji on iOS like you have on Android? Having to manually type :emojiname: every time is absurd. Yes, I know it shows a list when you start typing but it's still horribly cumbersome.


Can’t you just activate the iOS system emoji keyboard and use that? Won’t work for custom Discord emojis though.


I was obviously talking about the Discord emojis. I didn't think I needed to specify.


Discord Canary on my linux PC is unusable. It "stutters" during scrolling, typing and any form of interaction with it.

Is this what's expected from the app?


Sorry to hear that your Canary experience is not great :( Have you tried our stable Discord release? Canary will always have instability to it. If stable Discord still jitters for you please contact us (https://support.discordapp.com/hc/en-us) and we can diagnose better.


It’s not unheard of for alpha versions of applications to have issues. Does the release version also stutter?


Would you guys ever consider using Drab to interact with ReactNative on the frontend?


Why do I get feedback on discord, but not Skype for Business ? Have tried 3 different mics of different types and messing with the settings constantly. When I say feedback I mean my speaker output going as input to everyone else.


I'd suggest reaching out to our CX team (support@discordapp.com) - we really do care and you will get a reply :)

I'm not an expect on voice but iirc we do use a different codec than Skype so the audio is not going to be identical however, we have advanced settings in the `Voice and Video` section of the settings that allows you to enable/disable things like Echo Cancellation and Voice Suppression that could be the cause of the feedback.


Seems like something you should bring up with Discord's official support channel. This isn't really related to the article.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: