19 ms·
Good lord, this long-winded writing style is maddening to read! Here's what he changed: > Set<Thing> aSet = new HashSet<Thing>(); to: > Set<Thing> aSet = ne
by gmfawcett 7y ago
Good lord, this long-winded writing style is maddening to read!
Here's what he changed:
> Set<Thing> aSet = new HashSet<Thing>();
to:
> Set<Thing> aSet = new HashSet<Thing>(0);
His explanation:
"Most of these sets were empty for the entirety of their life, but each one was consuming enough memory to hold the default number of entries. Huge numbers of these empty sets were created and together they consumed over half a gigabyte of memory. Over a third of our available heap."
I'm not sure he ever got around to explaining how it saved "half a million dollars", though.
- awayfromhomenow 7y agono need to re-architect the program at that point, since heap pressure was reduced. The big takeaway for me here is to learn how your target language allocates memory for new objects.
- tlarkworthy 7y agoMy take home is focus on the thing that matters, and there is always low hanging fruit when something flips from "don't care" to "matters"
- nradov 7y agoIn general this is an example of how abstractions in high level languages become increasingly leaky as production workloads grow.
- davemp 7y ago> I'm not sure he ever got around to explaining how it saved "half a million dollars", though. Probably the classic software vanity formula: profit = efficiency
- sixothree 7y agoFTA: It involved some expensive re-architecturing. It required some very expensive new servers. It required a lot of even more expensive new licences for the third party components. It required delaying the features the business wanted until all this work was done.
- lioeters 7y agoI was about to write a similar comment but you wrote it a minute earlier. :) Seriously, the writing is long-winded and meandering. To add to the summary: "This particular trick also no longer works. As I found out while writing this article, modern JDKs do not allocate any space in a HashSet until something is added." So.. The article might have been better organized (and edited to 1/4 length) and focused on the section, "Four one liners every Java programmer should know". Unfortunately, it'd still be a click-baity title.
- sukilot 7y agoNumbers in headlines test better for SEO if they are odd, preferable prime.
- Tomte 7y ago> I'm not sure he ever got around to explaining how it saved "half a million dollars", though. Re-architecting the whole system, buying new licenses for third-party components, buying new servers (all explicitly named in the fine article) can easily cost half a million.
- deleted 7y ago[deleted]
- nradov 7y agoThe Java standard library also includes an empty set field, so as a performance optimization it's sometimes worth checking if your set will always be empty first and using that rather than instantiating a new HashSet at all. https://docs.oracle.com/en/java/javase/13/docs/api/java.base/java/util/Collections.html#EMPTY_SET https://docs.oracle.com/en/java/javase/13/docs/api/java.base...
- merb 7y agowell the empty set is itself immutable, so depending on the code base the new HashSet(0) was less code.
- mannykannot 7y agoTo be fair, this is just an example to illustrate the larger point, which, to me, seems to be that it is sub-optimal to be dogmatic over statements like "premature optimization is the root of all evil". It seems plausible to me that halting the re-architecting project would produce the savings claimed.
- rhizome 7y agoNot all optimization is premature!
- mannykannot 7y agoPrecisely -- dogmatism fails because it does not deal with situations that call for sometimes subtle, case-by-case judgement.
- theonemind 7y agoIn general, I’ve found some of the worst thinking in otherwise smart people from ideological thinking. My self-destructing rule of thumb is “don’t be an ideologue”.
- gwd 7y agoBut this isn't at all an example of "premature optimization". There was a well-defined, long-term issue they were having, and someone fired up a profiler, and showed that a particular change had a massive impact. That's exactly the opposite of "premature optimization".
- mannykannot 7y agoI think it is supposed to be an example of just-in-time optimization that almost did not happen. The implication seems to be that the architects did not even consider code-level optimization as a possible solution. Maybe the better message is "try to understand the causes of your problem before you try to solve it."
- cryptonector 7y ago
- hinkley 7y agoThe section above describes all the hardware, new licenses, and labor needed to fix the problem by scaling up. If anything I’d bet he underestimated the labor and opportunity costs.
- michaelt 7y agoHe describes the re-architecturing which was partly motivated by memory usage issues, and the change he made which saved memory, but he doesn't explicitly say "this allowed us to avoid re-architecturing"
- deleted 7y ago[deleted]
- hinkley 7y agoThere are two types of people in the world. Those who can extrapolate from incomplete data... The cynic in me wants to blame crippling licensing fees. Have you ever scaled up Oracle? Just typing that question gave me a nervous twitch.
- rolltiide 7y ago> this long-winded writing style is maddening to read! I learned not to read/watch things that don’t get to the point Often times they never do!
- jfz 7y agoHow do you know that they won't get to the point if you don't read/watch them?
- rolltiide 7y agoThe comments, skimming/scrubbing, the presence of an obligatory tl;dr
- tedunangst 7y agoRead one in four articles all the way to the end.
- Merad 7y agoIf you read the article (what a novel idea!) the author explains that his company was running into heap size limits. The company was preparing to tackle this problem with a combination of extensive refactoring, server upgrades, licensing expensive third party libraries, and delaying new features while all of the above was done. His "optimization" reduced peak heap usage by half, making all the changes unnecessary.
- jcims 7y agoHave you ever noticed that it's becoming more difficult to find recipes without a six page blog entry on top of it? This is kind of like that. I love the word bloviating for times like this. It's not really an onomatopoeia but something like it. It's also somehow clearly an insult. Edit: jrockway has actually changed my perspective on recipe thing...if people want to put a six page backstory and photos on top of a recipe that's completely their right and I would never suggest that more quality (?) content is a bad thing. My problem, it seems, is with Google putting that as the top result when I'm searching for a recipe. Esp when I'm on my phone in a store getting spammed by some captive portal while trying to figure out if the damn cookies I'm making need baking soda or baking powder.
- ljm 7y agoI used to write a lot of blog posts and, when it was to do with work, there was always some professional writer or marketing guy who said it was better to begin the post with some barely relevant fluff. I didn’t agree, and it didn’t fit my own writing style. But they insisted I do it, or they’d edit it in themselves. Same with this post. The ‘context’ wasn’t particularly enlightening. I thought I’d be reading a programming war story but there wasn’t any pay off.
- combatentropy 7y agoI've studied writing all my life, and most of the classics on writing would agree with you, such as The Elements of Style and On Writing Well. William Zinsser, the author of On Writing Well and a newspaper editor, talks about this very thing, saying that articles are often improved by cutting the first three paragraphs.
- cpach 7y agoYeah what’s up with all these new long-winded recipe sites? Is it a SEO thing?
- redis_mlc 7y agoIt's a "two-part greeting" thing. But this is HN, so nobody knows what that is here. :)
- minimuffins 7y agoThis writing style is useful for beginners. Imagine a reader who's not already an expert, who isn't familiar with the decades worth of back and forth discourse about tradeoffs between performance and maintainability. He provides some context and history and tells a little story. Tech writing needs more of that. Half a million seems like a good guess for how much the company would have lost paying developers and architects to re-design and re-implement the system, buy new hardware, new licenses for their third party software and the revenue they would miss out on by doing all that unnecessary work instead of building a profitable new feature.
- jmilloy 7y ago> This writing style is useful for beginners. The most useful writing, for both beginner and expert audiences, puts the most important content first, with supporting details later. Dispersing the lede late in the article serves the author/advertisers, not the audience, and is independent of whether the content contains context for beginners or a narrative style.
- acvny 7y agoAll this in the name of the almighty SEO optimisation.
- rb808 7y agoNext step is to make it a 45 minute youtube video.
- AstroJetson 7y agoExactly!! "Hi Astro here, you are watching this video because you want to learn how to framis and being an expert in framis I'm going to help. But first click on the subscribe button and make sure that you watch my other videos. In them I explain ...... And while we are here about to learn how to framis, lets take a quick look at the new gizmo that I bought, it has nothing to do with framis, but it's cool ..... Wow that was cool. So lets get to the framis, did you remember to subscribe. To framis you do the following (11 seconds of explain). Good luck on your framis and don't forget to subscribe. Going to close out now with a video of the cat. /sigh
- cpach 7y agoThis is one of the reasons why I almost never watch stuff on YouTube. I heard people who claim that they learnt how to barbeque, renovate, take good photos etc. by watching YouTube. I’m impressed, but what I don’t understand is how they managed to either sit through or filter out this kind of chatter.
- sarah180 7y agoThere's a difference, because something like "take good photos" is not a task with an algorithm. If somebody wants to know how to resize an image in Photoshop, you really just want to know which option in which menu and which default settings to use, followed by short (skippable) discussions of sampling algorithms and how resolution interacts with image size. YouTube discourages this kind of efficient information delivery, as Google's incentives drive it to encourage sustained attention. It's hard to build that kind of attention on "press this button and then that one." This is analogous to a laboratory session where you really want to learn by doing, and just need the recipe. However, learning to be a good photographer is not an algorithmic task—though it may involve them. Being good at something complex involves a comprehensive view and a value system to understand what's important and how many factors interplay. This is calls for a soft version of the academic lecture—something YouTube can do very well. YouTube can be fantastic at the latter: just avoid it for the former.
- deleted 7y ago[deleted]
- blfr 7y agoMost books should be blog posts. Most blog posts should be tweets.
- cryptonector 7y ago> I'm not sure he ever got around to explaining how it saved "half a million dollars", though. Me either. TL;DR. I did skim enough to get to the one-character change, and I instantly knew what the issue was: they were using Java. Ok, ok, just kidding, yes, pre-allocating what you're not going to need is premature optimization -- don't do it, except when it pays off.
- thraxil 7y agoIt seems like you were reading the article with a mindset like "how do I save half a million dollars in my code with a one character change?" and were annoyed to find a bunch of other stuff that didn't directly answer your question. But if you actually read the whole thing, it's clearly a meditation on the classic tradeoff of readability vs performance optimization, when micro optimizations are and aren't worth it, and how we should be deciding when to focus on one aspect or another. The single character change thing was just one particularly salient example that he uses to drive a point home. Reading it without a preconceived idea and letting the article itself explain its purpose to me, I found it pretty well written. There's been plenty written about this tradeoff over the years and this was far from the worst I've seen.
- barbarbar 7y agoWish I had read this comment before the post. Thank you.