The template error messages look great. I wonder if it’s worth writing a translator from clang/gcc messages to these ones, for users of clang and older gcc (to pipe one’s error messages to)
One of the big bottlenecks of plotting libraries is simply the time it takes to import the library. I’ve seen matplotlib being slow to import, and in Julia they even have a “time to first plot” metric. I’d be curious to see how this library compares.
I think one nice thing that we have tried to do is limit super heavy dependencies and also separate optional dependencies to streamline things.
The quickest install would be `pip install fastplotlib`. This would be if you were interested in just having the barebones (no imgui or notebook) for desktop viz using something like glfw.
We can think about adding in our docs some kind of import time metrics.
Seems like you can do this sort of speed up even without the 256 constraint. Just run this sped up version, but after each set of 256 iterations, dump all the 8-bit counters to the 64-bit final result.
Some people already mentioned this in the r/cpp discussion. Small correction: 256 is not the correct number of iterations, since if all elements in that slice are even, then your 8-bit counter will wrap-around to zero, which can lead to a wrong answer. What you want is 255 iterations.
I've looked at the generated assembly for such a solution and it doesn't look great. I'm expecting a significant speed penalty, but I haven't had the time to test it today. Will probably do so tomorrow.
255 is not ideal either because it results in a partial vector at the end of either 15 or 31 elements. 256-V where V is the vector size is better, so 240 for SSE2/NEON or 224 for AVX2.
This is still lower than optimal because the compiler will reduce to a uint8. Both SSE2 and NEON support reducing to a wider value by _mm_sad_epu8 and vpadal_u8, respectively. This allows for 255 iterations in the inner loop instead of 15 or 7.
And here's the benchmark output, on my machine: https://0x0.st/8SsG.txt (v1 is std::count_if(), v2 is the optimization from my blog post, and v3 is what you suggested).
Yeah, the difference you're seeing is likely due to the inner loop doing so few iterations, in addition to not being unrolled. A hand-rolled version doing 63 iterations of an x4 unrolled loop should be able to saturate the execution core (it'll be bottlenecked by load throughput). But it'll be tough to get the compiler to generate that without intrinsics.
The fastest thing I would think is to process 255 vectors at a time, using an accumulation vector with the k-th byte in the vector representing the # of evens seen for the k-th byte of the vectors in that 255-vector chunk. But, I don’t know how to make autovectorization do that. I could only do that with intrinsics.
This article presents a readable overview of today’s NBA trends, but IMO is too absolute in its judgment. Basketball is not a solved sport. There is still innovation, for example with OKC’s historically good defense that relies on playing 5 smaller but faster players. There are still good all-around players. There are still people that hit a lot of mid range shots. We have trends going the other way, sure, but they have their own set of tradeoffs and are neither a total solution nor totally embraced in the NBA. Teams will continue to evolve based on the talents of people at their disposal and their own innovative ideas.
In my opinion, the real problem with the NBA is that we no longer get the marquee matchups in the Finals that we used to during the 90s and 00s, mainly because the season is too long. An 82-game grind isn’t sustainable - it practically guarantees that stars like Giannis, Luka, or Jokic (or their key teammates) will get injured to the playoffs or not at all.
The fact that we’ve never seen Embiid vs. Giannis in the ECF, and that we’ll likely never get Giannis vs. Jokic, the two best players during the 2020s, in the NBA Finals says everything you need to know and it's a bummer.
Aside from 2021, I can’t remember another truly competitive finals where both teams had a real shot at winning. Maybe Boston wasn’t expected to fall so hard against Golden State, but matchups like DEN vs. MIA, BOS vs. DAL, or LAL vs. MIA felt lopsided—one team stacked with talent, the other never really standing a chance.
At this point, injuries, not players or teams, are deciding who moves forward.
> At this point, injuries, not players or teams, are deciding who moves forward.
Football is kinda like this at this point too. Some fraction of the top QBs are going to go down each year, and it feels like a limp to the finish.
That being said, somehow Wilt Chamberlain once played a season in which he only missed 8 and a half minutes total in the entire season, including OT. Amazing. Times have changed but that will never happen again now.
Soccer is slowly getting there. You play for your club in the series, the cup, some europa cup, now also the world club cup, then there's matches with your national team, world cup etc. They are now even contemplating having the world cup more often.
Having more games is an quick way to make more money, but in the long run it waters down the product.
> Wilt Chamberlain averaged more than 48 minutes a game during the 1961-62 NBA season, where he played an average of 48.5 minutes per game; this is considered one of the most remarkable feats in NBA history.
The real problem is the amount of ads and game breaks. Everyone knows basketball is about the fourth quarter so the league has backloaded ads. Now it routinely takes 20-30 minutes to get through the last 6 minutes of a game. Completely breaks the flow of the best part of the show. Second problem is that with the play in 2/3 of the teams make the post season so there is little incentive to try for a top seed anymore.
This is an interesting point. All the breaks also make it so that players get less tired from a cardio standpoint, are able to further exhaust their muscles, and leads to more injury.
I agree with the breaks, but there is a lot of incentive to make the guaranteed playoff seeding. You might only have a one game chance to make it into the playoffs otherwise.
It's weird because almost all of the levels below the NBA are better games than the NBA. Nobody really goes out of their way to follow AAA baseball teams, but college basketball and even some high schools are great games.
The pet theory is that the NBA is a RNG for gambling now the game isn't really the game. TV is near death, so gambling is the only source of revenue that can possibly replace the big TV deal.
My theory is that it’s only a matter of years before the Saudi’s launch a league. It’ll scoop up a large swath of international players including NBA superstars. Jokić becomes very famous and wealthy.
This is why I don’t comment on the internet anymore. You exist in the alternative reality in which every back and forth is a polarized ridiculous showdown.
Jokic is not famous outside of basketball. The Saudi’s would make him so wealthy he’d seem poor today by comparison.
I agree with your point and response. This activity of being players overs to new leagues run by Saudi or adjacent countries has been huge in almost every major sport. Some with much more success than others.
I think a big reason we don't have competitive finals is generally not having a harder salary cap and allowing max for contracts. If a player really is that good they should take up 50% of the cap and to balance it out have terrible other players.
Anything else allows stacking value above cost and leading to team imbalances.
The real problem is the players don’t give a sh*t about the fans any more. You need no better example of that than the All star game tomorrow. In the 90’s it was an amazing, competitive game between the best players in the league. Now…the players can’t even be bothered to jog up and down the court. Load management: players claim their bodies are delicate and can’t play too many games. Why would I want to buy tickets to a game or watch on TV if there’s a good chance the stars aren’t even playing. Guys the 90’s played every game. Players now sign a 5 year contract and the next day ask for a trade. Look at Kevin Durant - great player, but has forced his way out of 3 teams and it’s about to be a 4th. Too much guaranteed money means too little incentive.
If the players don’t care about us, why should we care about them?
They've gotta change up the all star format then. NHL didn't do all star stuff this year; instead they're running a pseduo-national teams tournament with NHL players, and the four teams are all top players playing really hard. I don't know if there's enough non-US players in the NBA to do the same thing, but it's an idea.
The 90s All Star games were 160-150 affairs and had all sorts of sideshows. And players should absolutely maximize wealth which includes protecting their health. And there has never been a time when every person played all out, that’s just nostalgia creeping up on you.
I think the difference is that teams are more cautious because they don't want a season disrupted by a major injury. Zion the other day said that the Pelicans were the limiting factor in his sitting back-to-backs. Players frequently come back on minutes restrictions (Kawhi previously, Exum currently).
"Only 3s and layups" is the current easiest strategy to build a proficient offense, but it's certainly not the only way.
You don't even have to look far for an example. The Denver Nuggets won a championship a year and a half ago while nearly attempting the fewest 3s in the league.
> In the past, the team built its roster around a big name like Shaq. Most of the offense were from the center. This has now changed...
Is the author not aware of Giannis, Jokic, Embiid, (Wembanyama... soon)? The winners of the last 6 MVP awards? If there were enough talented bigs to go around, every team in the league would be building around them because it works really, really well.
wow really? Did soccer also go through a statistical revolution? I don't watch soccer at all and am pretty surprised to hear this. Did all the teams converge on a winning solution?
because of the structure of soccer (completely different to basketball, it is an invasion sport but statistically very dissimilar), it has completely reversed the ordering of the sport
there is significantly more strategic diversity, and teams that were unable to compete ten years ago are now able to compete effectively with wealthier teams (there is no catchup mechanic in soccer unlike US sports, ffp rules have also played a role but in the EPL at least the primary factor has been smaller teams using their budget more effectively)
the most recent changes have been: premium for coaches (distinct from managers) has increased significantly and a greater focus on set pieces (but this is going back to the future, twenty years ago EPL had a period where teams did this to level the field...today, they are doing this and it appears to be permanent).
it is also worth adding, i would say the majority of clubs that have tried a naive statistical approach have failed. Liverpool tried and are leading but are completely reliant on one player, Arsenal are doing better but reliant on set plays and their recruitment has been poor (they have had a stats team for over ten years at this point), the teams that have done well with stats (Brighton and Brentford) have a hybrid approach (and Brighton is further down the road with this, and have done significantly better...they use non-public resources far better, integrated with sport science, etc.)
if stats in soccer is a 90-minute game, we are still at minute 5
he has changed strategy multiple times based on team composition
possession-based at Barca, more pragmatic at Bayern, first City teams used wing-backs and insane attacking then acquired more defensive players and went back to suffocating opposition
playing out from the back is ludicrous only because teams who are unable to play that way insist on doing it, and the credibility of that strategy as a global minima has already passed (largely due to the issues Burnley had last year and Spurs/Southampton had this year)
this year has proved that there are multiple ways to win. imo, the most boring manager is Arteta who does the defensive stuff without (almost) any attacking players (and is, thankfully, failing...the worst thing would be a manager playing like a Serie A side and winning)
Pretty much all teams play more or less the same style of building up with the goalkeeper because data shows that even though you suffer more goals it's offset by scoring more.
It seems like a very brief and abrupt article. I can understand the part about strategy of three pointers. But how does all the technology and analytics actually change the game, besides "improving form"? Has it allowed better calculation shots with the best odds for a given player? Has it discovered other team's weaknesses to exploit? Etc
Analytics leads to teams converging on the same strategy, at least on offense. The data makes it clear that you should almost never being taking mid rangers or running iso sets. So now those plays are gone from the game.
When analyzing non-computing problems through a computer science lens, the human element merely muddies the path to a concrete answer. It’s best to avoid that ambiguity and complexity.
I think that's unfortunate: the article still has that title, and knowing it wants to lead to such an absolute conclusion can tell a prospective reader if they are interested to be led down that path or not.
That approach to baity titles doesn't generalize, I'm afraid—neither to users nor to titles. In general, baity titles cause threads to fill up with responses to the provocation in the title, making for shallow and ultimately off-topic discussion.
It's standard practice on HN to replace these with titles that are more accurate and neutral, but we always try to do this using representative language from the article itself. Usually that's a subtitle, or the HTML doc title, sometimes it can be the URL slug, or even a photo caption.
Often there's a sentence at the start of an article that walks back the title and says what the article is 'really' about. It's as if the title 'takes' too much and then the article 'confesses' and gives most of it back. These walkback sentences often make good HN titles because they represent the article more accurately. That's what I used in this case.
You are right that it does not generalize: but in this particular case, it was really reflective of the article which was shallow itself (IMO at least).
So I guess that the rule doesn't generalize either, but I can at least understand the reasoning behind it and accept that it might work better on average — thanks for the explanation!
Would allocating a 640-byte string initially really be the right tradeoff? It seems like it could result in a lot of memory overhead if many small strings are created that don’t need that space. But it does save a copy at least
As for the int-to-string function, using the division result to do a faster modulus (eg with the div function) and possibly a lookup table seem like they’d help (there must be some good open source libraries focused on this to look at).
> Would allocating a 640-byte string initially really be the right tradeoff?
It depends, presumably the generated JSON string would quickly be written down inside something else (e.g. sent as HTTP response or saved in database), so the object slot would be freed rather quickly.
Do you expect that Apple’s bigger security initiatives, like pointer authentication and writing the OS in a memory safe language, will improve the situation?
All these things increase attacker costs. In the current landscape, increasing attacker costs has the effect of shaking out some of the lower-rent players in the market, which may put some targets out of reach of lower-caliber threat actors.
The problem you have over the medium term is that CNE is incredibly cost-effective, so much so that you need something like multiple-order-of-magnitude cost increases to materially change how often it's applied. The alternative to CNE is human intelligence; it competes with literal truck rolls. You can make exploits cost 10x as much and you're not even scraping the costs just in employee benefits for an alternate intelligence program.
What that means is, unless you can foreclose on exploitation altogether, it's unlikely that you're going to disrupt the CNE supply chain for high-caliber state-level threat actors. Today, SOTA CNE stacks are probably available to the top IC/security agencies† of all of the top 100 GNP countries. It probably makes sense to think about countermeasures in terms of changing that to, like, the top 75 or 50 or something.
I think we tend to overestimate how expensive it is for adversarial vendors to keep up with countermeasures. It's difficult at first, but everything is difficult at first; I vividly remember 20-30 extraordinarily smart people struggling back in 1995 to get a proof-of-concept x86 stack overflow working, and when I first saw a sneak preview of ROP exploitation I didn't really even believe it was plausible. As a general rule of thumb I think that by the time you've heard about an exploitation technique, it's broadly integrated into the toolchains of most CNE vendors.
Further, remember that the exploit development techniques and people you've heard about are just the tip of the iceberg; you're mostly just hearing about work done by people who speak fluent English.
† Reminder that customers for CNE vendors usually include many different agencies, invoiced separately, in the same governments.
Reminds me of the book “this is how they tell me the world ends” - a history on cyber weapons. It’s written from the perspective of a journalist without a comp sci background but delves deeply into the topic of how cyber weapons are procured, priced, and sold to multiple agencies in the same government. It’s unfortunate these are used for exploits and not for reporting bugs or vulnerabilities. Stockpiling exploits only makes everyone less safe
I mean, I agree, but also it doesn't matter than I agree, because wanting everyone to be altruistic --- no, to share the same notions of "altruism" that we do, since quite a few hypercapable exploit developers don't agree that their home states shouldn't have access to whatever signals intelligence they want --- won't make it so.
Very fun read! I’m curious though, when it comes to non-Ruby-specific optimizations, like the lookup table for escape characters, why not instead leverage an existing library like simdjson that’s already doing this sort of thing?
In short, since `ruby/json` ships with Ruby, it has to be compatible with its constraints, which today means plain c99, and no c++. There would also probably be a licensing issue with simdjson (Apache 2), but not sure.
Overall there's a bunch of really nice c++ libraries I'd love to use, like dragonbox, but just can't.
Another thing is that last time I checked, simdjson only provided a parser, the ruby/json gem does both parsing and encoding so it would only help on half the problem space.
The benefit of a Ruby-specific JSON parser is that the parser can directly output Ruby objects. Generic C JSON parsers generally have their own data model, so instead of just parsing JSON text into Ruby objects you'd be parsing JSON text into an intermediate data structure and then walk that to generate Ruby objects. That'd necessarily use more memory, and it'd probably be slower too unless the parser is way faster.
Same applies to generating JSON: you'd have to first walk the Ruby object graph to build a yyjson JSON tree, then hand that over to yyjson.
All of the would be a big savings in code complexity and a win for reliability, compared to doing new untested optimizations. If memory usage is a concern, I’m sure there’s a fast C SAX parser out there (or maybe one within yyjson)
I don't understand what you're getting at. If performance is a concern, integrating a different parser written in C isn't desirable, as it would probably be slower than the existing parser for the reasons I mentioned (or at least be severely slowed down by the conversion step), so you need to optimize the Ruby-specific parser. If performance isn't a concern, keeping the old, battle-tested Ruby parser unmodified would surely be better for reliability than trying to integrate yyjson.
What I love about this article is it's actual engineering work on an existing code base. It doesn't seek to just replace things or swap libraries in an effort to be marginally faster. It digs into the actual code and seeks to genuinely improve it not only for speed but for efficiency. This simply does not get done enough in modern projects.
I wonder if it was done more regularly would we even end up with libraries like simdjson or oj in the first place? The problem domain simply isn't _that_ hard.
Bear in mind that: the author is part of the ruby core team; json is a standard lib gem; the repo from the json gem was in the original author namespace; the repo had no activity for more than a year, despite several quality MRs.
It took some time to track and get the original author to migrate it to the ruby team namespace.
While I'm glad they to all this trouble, there's only a few who could pull this off. Everyone else would flock to or build a narrative.