social network soup isaiah.micro.blog/2018/08/1…
social network soup isaiah.micro.blog/2018/08/1…
If you’re just getting coding, then this looks like a fun way to keep the good habit going: 100daysofcode.com
If you’re like me you’ve been coding pretty much every single day since 1981 and maybe doing a 100-days of no-code would be a bit more healthy.
I don’t normally write stuff on FB, but this was for my relatives mostly and the only platform they use is FB.
Anyway, this is related to a post recently how I taught my son to reduce a “Karnaugh map”.
. @manton suddenly my timeline is very manton focused.
i don’t know if it’s significant, but it seems to have happened after i followed someone.
Visually stacks are organized like containers. Each container contains other stacks, some of which might be containers themselves. Unsurprisingly this is modeled internally as a tree. Each tree has many branches, some of which might have branches themselves.
There are dozens of reasons to traverse the tree: to search it for specific objects or properties, to modify it in a dozen different ways, or to collect data from it.
Recently I rewrote one of the slow data-collection traversals. The goal is to collect a bit of data from each node of the tree. But in this case the data from each parent node is just the concatenation of all of the child-node data. When the data of the parent relies on the child a depth-first traversal is required.
Until recently this particular traversal was infrequent and not much thought was given to optimizing it. However recent changes make it part of a critical path. It’s slowing other parts of the user experience and that means it’s time to optimize!
The current method of traversal is a vanilla for loop. It accumulates the collects the data from its children and concatenates before returning the result to its parent. At the leaf nodes there’s a computationally expensive task.
This cries out for concurrency. The computationally expensive tasks are being run one at a time. I have a 12-thread Mac Pro on my desk and even on older hardware most users can run 4 threads. Most of those CPUs are sitting idle while just one is running all those expensive tasks. Why not use that hardware?!
warning: Obj-C ahead. Stacks is a 3rd-party plugin to RapidWeaver. Stacks can’t predict which version of the Swift runtime will be included in RapidWeaver, or if it will be included at all. Until a stable Swift runtime ships in macOS, plugins like Stacks can’t be written in Swift.
So, as a starting place I converted all the single-thread for loops into
enumerateObjectsAtIndexes:Options: calls with
Options set to
NSEnumerationConcurrent. Returned data comes back in random order now, but for this particular task the collected data can easily be reordered later without any extra work.
First test: Measure the throughput of the old vs. the new methods. I made a relatively small test case and repeated it 1000 times to get a reliable average measurement. Results: the speedup is about 8x. Not quite 12x (the number of threads available on this machine), but substantial. Even on minimal hardware the speed improvement should be obvious.
Second test: Try it out. Actually open a slow file in RapidWeaver and see how fast it is. Uh oh, the speedup’s gone. In fact the slow file is now slower than ever. Noticeably slower. Maybe 2x-3x slower. Ugh! What happened?!
After a day of analysis the results are that the overheads of constructing and managing operation queues for each node scale geometrically with both the width and depth of the tree. In other words a large real world tree with depth of about 15 and width over 30-50 has so many operation queues that the the CPUs are hardly ever working on the original problem. Most of the effort is spent allocating, managing, and deallocating queues.
The takeaway is that blindly converting a complex task to concurrent operations is a bad idea. And more specifically using NSEnumerationConcurrent in a recursive task is a bad idea. It’s best to call enumerateObjectsAtIndexes only once (or just a few times) on all the data. The operations themselves are very efficient but creating, managing, and deallocating queues is expensive.
As a final note my eventual use is a hybrid. I gather up the expensive leaf node tasks in a simple linear for loop. Then run all the tasks in a single concurrent enumeration. The result is a bit less elegant in code, but is actually faster than the first try. The real world speedup is significant, but not huge: about 3x on my 12-thread machine. And there is some memory overhead as well. It should be noticeable on slower hardware, so I’ll keep it, but probably not a huge speedup for most users. I’ll have to keep hunting for more optimizations to make this plugin as fast as it should be.
ten years indie.
it was both easier and harder than i ever thought it would be. and in ways that i never could have imagined.
i’m a bit tired now. i like being independent, but working for the man, and not having to think about the challenges of running a business like insurance and budgets, looks more attractive all the time, even though i know that those things are part of the reason i wanted to be independent.
the high of creating a product people love is powerful and amazing. the low of creating something that people don’t care about at all is amazingly powerful too.
without a rigid schedule i work whenever i feel most creative. this is wonderful, but came with an unexpected twist. no matter how hard it try to avoid it, my natural tendency is to do most of this work in the middle of the night while other people sleep. i have no idea why.
it’s very difficult to feel successful. i know that i have achieved much more than i thought i would, but successful is a sisyphean bolder.
i’m going to try to stop pushing the bolder from here on out. i’m not going to worry about whether i am successful or not. ten years is plenty of that.
when i quit my day job i hoped i could stay independent for one year, working on my own ideas at my own pace. for me, one year meant success. everything more was just icing on the cake.
10 years of icing.
tried the firmware update a couple more times just for fun. nope. same deal.
so, i’m restoring to a second drive and i’m going to try to install Mojave directly from there.
trying to install high sierra on the external drive – but no can do. installer just demands i install a firmware update over and over again… despite high sierra already running on the machine currently and installing the update twice again.
step 1 complete: new video card installed.
unfortunately i couldn’t make all the video cards fit. i think even if i could it might have been questionable for the power supply.
new video card is here. it’s time to visit the desert.
You know all those great pictures of Obama? They’re from one photographer. He has a book (and a nice instagram account). kottke.org/18/07/sha…
made pho 🍲 tonight. my skills and supplies are getting much better.
downside: i ate too much. i’m so full it hurts.
i think i have imposter-syndrome, but recovering from surgery. is that a thing?
i feel like a total slacker lazing around the house, but every time i leave it’s super obvious that i’m still a total gimp.
btw: for those looking for more kiwi posts. sorry. i’ve been really busy with real work recently and it hasn’t left much gas in the tank at the end of the day for side-project code.
the ability of JS promises to be called by multiple asynchronous consumers is a powerful pattern that i didn’t quite see at first.
i’m still not a super fan of promises. but that bit is a pretty cool to have when building event driven apps.
i’m pretty sure getting a second round of pain medication after a surgery is more difficult than getting a second round of funding for a silicon valley startup
Le Tour day 1: Wow, so much happened from what seemed like a few minor crashes. The GC is truly wide open.
BTW: I’m absolutely a cycling nut. If you’re not, or worse, if you’re a nut too – then you might want to mute me for the 3 weeks to avoid cycling/spoilers.
anyone know how to change the default RSS reader in macOS nowadays?
i’ll just go read some open source, see how other devs are doing this…
OSS #1: pure strict functional: no loops, no ifs, no local vars — just crazy inside out unreadable code
OSS #2: same method: 9 indents deep with 3 nested for loops and 3 ifs
OSS coding style is like: 🤯
my biggest hurdle to blogging is my very poor ability to edit my own writing. i seem unable to find mistakes until after i hit the post button. and the fear that i’ve missed a few mistakes has kept me from clicking the post button far too many times.
i’m trying to just roll with it and let the words fly. it’s tough to look up at the screen and see the obvious mistakes, but it’s better than never posting anything at all.
so please bear (bare?) with me while i stumble through this experiment and try to keep clicking post.
after my recent switch of text editor (yes, again. shut up.) to VS Code mostly due to built-in typescript support and a quickly growing extension community i’m ready to report back with a mini review: first impressions
it’s ok. i’m really frustrated by the scrolling and vi quirks, but the extension API has pulled me in. but despite the UI discomforts i seem very productive inside the app, which is a good sign for the long haul – so i’m going to stick it out for a bit and see how it goes.
usually on the 4th we go to watch nearby fireworks in Cedar Park (hi @manton). their display isn’t huge, but i like the small town feel of the get together with local food trucks and bouncy houses for the little kiddos. it’s craziness, but on a very small scale.
this year i can’t go because i’m not quite mobile yet after recent surgery. i have to admit, even as dorky as it is, i was feeling pretty bummed about missing it.
but the weather in Austin is always a bit of a crapshoot. and today we rolled: thunderstorm ⛈ a pretty good one too. i’m hoping the downpour will add a couple inches to the lake.
so fireworks and picnic plans are right out — hip surgery or no.
so… thanks universe for giving me that one and providing me with natures own fireworks 🎇⚡️🌩
my feelings of missing out are hugely diminished. board games with 🍔 & 🌭 grilled under the back porch eves will be just fine.
happy independence day everyone!
now, please go read The Declaration of Independence. really. don’t just brush it off. you’re a grownup now. then read it’s sister document France’s Rights of Man, too. you’ll be glad you did. it only takes s few minutes.
we all share inalienable rights. and the rule of law applies to every one of us, billionaires and monarchs and homeless junkies and even Honduran children fleeing persecution.
these rights are outside of politics and time and faith and everything else. it’s really important. and i think we’re going to really need to remember that this next year.
it’s a bit of web magic that builds sites — on the client side from data in the URL
it’s such an interesting idea. i feel there must be more that it can be used for.