Mathias Bynens, a web developer and JavaScript engine contributor, writes about Unicode, JavaScript internals, and web standards.
HN commenters link his URL validation regex demo, his JavaScript Unicode essays, and his globalThis notes, calling them worth saving.
> If it's really common for everything to become a performance bottleneck, it's worth profiling from the start so that you avoid having major pitfalls anywhere. If it's rare and exceptional, FFI for those cases is fine.
You can have it both way, code evolve. It is pretty common in performance critical code that a minor, almost never call function in one scenario, become a performance critical bottleneck in an other. If you already played with large scaled simulation software, this happened almost every week depending of your inputs on what you are interested to simulate.
> On the contrary. Plenty of people do those kind of things in, say, Java. They require knowing about compiler internals and using unsupported hints, or even bypassing parts of the compiler
No it's not again. I have been developing in C++ for 15 years, including in the HPC world and I (close to) never had to touch a compiler internal.
The language gives you what you need for performances, you do not need to play with that.
At the opposite JIT compilers like V8 or Java are monster of complexity very sensible to side effect [1] and controlling things like "Does this data fit in my L2 cache ?" in them is close to impossible because even things like "Where are my data and what are there size ?" is an hard question.
Once again, there is theory and there is practice.
Theory is what you say. Practice is that 98% of performance critical software in HPC, game industry, physics and High Frequency Trading is in…
Both of your examples have invalid sort comparator functions.
A JavaScript sort comparator is required to not only return a positive or negative value, it must handle all three cases: greater than, less than, or equal. When the arguments compare equal, the comparator must return 0.
Returning only a positive or negative value is a very common error. (I don't mean to pick on you for this! I have seen the error so often that I hope this may be helpful for anyone writing a sort comparator.)
The invalid comparator will force the normally stable sort to be unstable, because sort() now has no way to know that two items should be considered equal and their existing order preserved.
Let's demonstrate with the "doggos" example that the article links to:
https://mathiasbynens.be/demo/sort-stability
The code starts with this array:
const doggos = [
{ name: 'Choco', rating: 12 },
{ name: 'Devlin', rating: 13 },
{ name: 'Eagle', rating: 13 },
{ name: 'Jenny', rating: 13 },
{ name: 'Kona', rating: 13 },
{ name: 'Leila', rating: 13 },
{ name: 'Milly', rating: 14 },
{ name: 'Molly', rating: 12 },
{ name: 'Nova', rating: 12 },
{ name: 'Oliver', rating: 13 },
{ name: 'Patches', rating: 14 },
];
It uses this valid comparator:
doggos.sort( ( a, b ) => b.rating - a.rating );
(Note that this implements a reverse sort as can be seen in the output on the test page.)
Subtraction provides the proper…
In my own experience, the biggest unicode implementation failure was MySQL's choice of using 3-byte BMP Only UTF-8 instead of a full 4-byte Unicode support.[1] In retrospect, their decision to go with a broken subset implementation had caused more trouble, confusions and incompatibilities than their claimed benefits of speed/performance/simplification. Do a simple google search will see almost everyone recommends avoid `utf8` and use `utf8mb4` instead. [2][3][4]
As a result, if your MySQL databases/tables/columns are using `utf8` instead of `utf8mb4` (a MySQL invention) charset, you cannot store / retrieve emoji characters properly.
[1] https://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html
[2] https://mzsanford.wordpress.com/2010/12/28/mysql-and-unicode/
[3] https://mathiasbynens.be/notes/mysql-utf8mb4
[4] https://www.drupal.org/node/1314214
Taking a look at that, I think shapes would still work; [1] has some background material on them, but dynamically changing data is what shapes are for; you check if you should update an object's shape when assigning to it, and can JIT based on the type (you ought to be able to handle getattr and setattr with this too, JITting to a direct call to that method when it's necessary). Where this completely falls down in optimizing Python is that it changes the object layout, so you can't pass these to CPython without making them generic and converting them back after. Converting the layout to be generic would be a deep copy (which of course is semantics-breaking), converting it back wouldn't even be possible if the C code kept a reference to it around.
[1]: https://mathiasbynens.be/notes/shapes-ics
> It's one less network request, saves bandwidth
Given that most stuff these days is packed together with Webpack or at least concat'd together, you don't really save much, plus jQuery in gzip'd form is clocking in at <30 kB anyway (https://mathiasbynens.be/demo/jquery-size).
> and pretty much unmaintained code (at this point, the jQuery github is as good as dead, unlikely to see major releases any time soon)
So what? Software can very well be "done", there is no need to always evolve and evolve. As long as there is no security issue left unsolved, though.
In addition, if you're rebuilding half of it on your own anyway, chances are high you'll miss some weird corner case that jQuery solved years, or decades, ago.
I found [1] to be a pretty good summary of the key concepts that support the claim. The article, unfortunately, doesn't come right out and say it. But, it talks about how object shapes (a common JS object model) can be used as guards for inline caches (IC) to generate efficient machine code for property access. If you add a new property, you change the shape, which causes the cache guard to fail. That leads to deoptimization since the assumptions made about the call site when the code was compiled no longer hold. That call site is now either polymorphic or megamorphic, depending on the type of IC used and its level of polymorphism.
[1] -- https://mathiasbynens.be/notes/shapes-ics