Live data from Hacker News

Node.js: Some quick optimization advice

medium.com

61–70 of 75 posts

Re: Node.js: Some quick optimization advice

#61
post #19
post #15

Earlier quoted context omitted.

As others have said, you can always strip comments in production builds. But I agree that this is utterly silly - I'd like to see a movement to deprecate including comments in parsing at all. Anything that makes use of such a feature is hacky weirdness from the start.

Function.prototype.toString() should be deprecated anyway. There are very few to no legitimate uses of it that are any better than awful eval() hacks. Re: this comment, if you just don't make huge comments inside the body, but rather above it - as is the usual standard - this is less of an issue.

> Function.prototype.toString() should be deprecated anyway. There are very few to no legitimate uses of it that are any better than awful eval() hacks.

The toString() on a function is very useful in more ways than awful eval hacks. The most useful way is how I use it in msngr.js for creating keys for methods that handle events.

So let's say your custom object has a way to handle events. Surely you want to allow more than one method to be hit for each event, right? So internally to your object you keep track of this by the method's contents as a sort of key or hash that always points to that specific method. Then you can remove handlers by simply passing in a method. No requiring special keys or anything to identify a function as a function is its own key.

Make sense? It's most useful for developers who work on frameworks or objects that require some custom eventing that can be used by multiple places.

If you really want to deprecate this functionality then you need to provide a way to hash to create a unique key based on a function itself. The only other way around it is adding more verboseness to the language or event handler calls which doesn't add anymore clarity.

Re: Node.js: Some quick optimization advice

#62
post #60
post #52

Earlier quoted context omitted.

In this one context, this one micro-optimization applies but for 99% of other cases, they don't (and shouldn't). Note the 'benchmark' in OP is run 500 million times to see the performance difference. This is definitely not a common scenario.

For me, it's more the principle of the thing. This just seems like an insane way for an interpreter to behave. Even more insane is the proposal of minifying server-side JS!

Not that insane considering many people are using things like Babel to run ES6/7 code. If you're already compiling that code to ES5 for production, there's no harm in also minifying things.

Re: Node.js: Some quick optimization advice

#63
post #41
post #30

This is a good thing to raise awareness of, but the solution is poor advice. Asking developers to remember the "gotcha" of 600 characters is not really viable. Instead, if this is important to you, consider the addition of minification or comment stripping to your production deployment process. Minification will also make the variable names and syntax use shorter, saving you further precious characters. Learn the pro…

In the context of the article being on nodejs code; I don't know about other developers, but I don't minify my production nodejs code because it runs directly on the server. Whether I have `var nameThatIsStupidlyLong` or `var nTISL` doesn't make a difference because size of code isn't a concern. What do other developers out there do?

I use https://babeljs.io/ to compile es6 code for production. It could support this kind of transformation though I'm not sure if it does by default.

Re: Node.js: Some quick optimization advice

#64
post #41

Earlier quoted context omitted.

In the context of the article being on nodejs code; I don't know about other developers, but I don't minify my production nodejs code because it runs directly on the server. Whether I have `var nameThatIsStupidlyLong` or `var nTISL` doesn't make a difference because size of code isn't a concern. What do other developers out there do?

I use https://babeljs.io/ to compile es6 code for production. It could support this kind of transformation though I'm not sure if it does by default.

Babel doesn't, by default.

Re: Node.js: Some quick optimization advice

#66
post #41
post #30

This is a good thing to raise awareness of, but the solution is poor advice. Asking developers to remember the "gotcha" of 600 characters is not really viable. Instead, if this is important to you, consider the addition of minification or comment stripping to your production deployment process. Minification will also make the variable names and syntax use shorter, saving you further precious characters. Learn the pro…

In the context of the article being on nodejs code; I don't know about other developers, but I don't minify my production nodejs code because it runs directly on the server. Whether I have `var nameThatIsStupidlyLong` or `var nTISL` doesn't make a difference because size of code isn't a concern. What do other developers out there do?

[deleted]

Re: Node.js: Some quick optimization advice

#67
post #42

Earlier quoted context omitted.

it's incredible that that project has 11,000 commits, a huge amount of effort has gone into it but the code is really unpleasant to read. I feel like I must be missing something about FOAM - who is using it and why?

Let's stop trashing on people's work. The success of an endeavor is proportional to the number of shitty hacks that have come before it. Sometimes this it true in a literal sense -- sometimes a project consists of shitty hacks. But the astute reader will notice that a hack is only known to be shitty because someone did it , and had the courage to make their example public. Do we reward their courage? No. We act like…

Most everyone agrees with you in general about the usefulness of "trashing other people's work", but I think your response here is disproportionate to the circumstance.

Re: Node.js: Some quick optimization advice

#68
post #51

Earlier quoted context omitted.

> Things happen as they are parsed. If comments aren't completely ignored by the parser, then there has to be some case where a comment inside a function has an observable effect?

Yup, see @pauljz's comment above - https://news.ycombinator.com/item?id=10375297

I still don't understand that. Function.prototype.toString() wouldn't break because the parser stripped the comments, it would just output the source without comments? Does any code anywhere depend on the comments being preserved?

Re: Node.js: Some quick optimization advice

#70
post #34
post #19

Earlier quoted context omitted.

Function.prototype.toString() should be deprecated anyway. There are very few to no legitimate uses of it that are any better than awful eval() hacks. Re: this comment, if you just don't make huge comments inside the body, but rather above it - as is the usual standard - this is less of an issue.

Every JS dependency injection framework that I've ever seen uses it.

Serious question: why use a dependency injection framework with JS?
Post reply on HN