HNHacker News
TopNewBestAskShowJobs

khold_stare

198 karma · joined December 20, 2012

submissionscomments
khold_stare··on Nothing to watch – Experimental gallery visualizing 50k film posters
That list has Avengers Infinity War and Endgame on it by the way.
khold_stare··on On latency, measurement, and optimization in algorithmic trading systems
In trading all threads are pinned to a core, so that scenario doesn't happen.
khold_stare··on Six months into congestion pricing, more cars are off the road
Except for the Ubers, everything you listed that was added, moves more people than cars do. Public transit, bike lanes, walkable areas provide viable alternatives methods of transit so you no longer need to use a car. And those cars have huge costs to residents - noise, pollution - that they dont pay for. Congestion pricing literally is a price to pay if you refuse to use anything else that is more efficient in a dense city.

Also your comment on the "Bankrupt MTA". Public transit is just that - PUBLIC transit. It is not supposed to make a profit, the same way highways for cars are a public good. When is the last time you complained that your taxes are too high because of all the road maintenance? Those damn highways better make a profit!

Look at the data before you gobble up right-wing misinformation. Do you even live in NYC?

khold_stare··on But good sir, what is electricity?
Thanks for the kind words! For anyone curious to dive deeper into the crazyness that is quantum mechanics I can highly recommend a few resources:

- Sean M Carroll's work, in particular his Biggest Ideas in the Universe books: https://www.preposterousuniverse.com/biggestideas/

- Artur Ekert, basically the father of Quantum Cryptography has an amazing course for free on youtube: https://www.youtube.com/@ArturEkert . It's a very precise and understandable explanation of quantum computing, and some of the math that is involved with quantum mechanics.

- If you have hours to spare, watch Richard Behiel's videos on Youtube. He's like the 3Blue1Brown of Quantum Physics. His latest video on superconductivity and the Higgs Field is almost 5 hours long (!!!) https://youtu.be/DkH1citHtgs?si=-yQNYDu9TlTpE1A0 . It builds on his other videos, so I'd recommend starting at the beginning.

khold_stare··on But good sir, what is electricity?
Superconductivity is fascinating. I don't know how people were able to come up with the explanations. Crudely, the reduced temperature means less jiggling of the metal lattice. This in turn makes it possible for the nuclei to be pushed around by electrons to form essentially sound waves (phonons) in the lattice (think of the lattice compressing and expanding due to interplay with electrons). At a certain temperature and therefore a certain frequency of lattice oscillation, electrons pair up to form "Cooper pairs" - they move in concert due to the lattice movement. What's crazy is that cooper pairs become a sort of pseudoparticle, and their quantum behaviour is different to regular electrons. Cooper pairs have integer spin (as opposed to half-integer spin), so they no longer obey the Pauli exclusion principle and all the electrons in the entire material basically form one giant condensate that extends through the whole material and can all occupy the same lowest energy quantum state.
khold_stare··on The young, inexperienced engineers aiding DOGE
Yep! That's why I said it _sounds like_ a conspiracy theory. Just hope it can be halted in time.
khold_stare··on The young, inexperienced engineers aiding DOGE
This will sound like a conspiracy theory, but this is the playbook of Curtis Yarvin, specifically the "RAGE" step - Retire All Government Employees. Some references:

Watch the whole video (posted months ago predicting all these actions), but here is the relevant section: https://youtu.be/5RpPTRcz1no?t=1201

NYT interview: https://www.nytimes.com/video/podcasts/100000009910862/curti...

Gil Duran did a lot of the reporting on this. https://www.thenerdreich.com/the-network-state-coup-is-happe...

khold_stare··on Dell ends hybrid work policy, demands RTO despite remote work pledge
The comment about an "email chain could have been a 30-second chit chat" is such a straw-man argument. On top of that, forcing everyone to commute up to an hour each way is a blatant disregard for people's personal time. How productive would the workforce be if the commute counted as work hours?
khold_stare··on Four limitations of Rust's borrow checker
Isn't that the opposite of the intended implementation? I don't write Rust, but I think your implementation will always return either `None` or the "fallback" value with the `"-default"` key. In the article, the crucial part is that if the first `map.get_mut()` succeeds, that is what is returned.
khold_stare··on Show HN: Brisk – Cross-Platform C++ GUI Framework: Declarative, Reactive, Fast
Why is heap allocation and shared_ptr required? Can't you have the user store the widgets in whatever manner they want, as values?
khold_stare··on Move semantics in Rust, C++, and Hylo
I see some confusion in the comments about C++ moves. I wrote an article in 2013 after it clicked for me: https://kholdstare.github.io/technical/2013/11/23/moves-demy... . It goes over motivation, how it works under the hood etc, has diagrams if you are a more visual learner.
khold_stare··on Plutocrat Archipelagos
I think you missed his point completely. The point is that money removes the consequences of their and other's actions. Without this visceral understanding of the world, those people are not fit for power.
khold_stare··on Valkey achieved one million RPS 6 months after forking from Redis
The other comments have mentioned the tools. On linux, there's good old perf.

There's `perf stat` that uses CPU performance counters to give you a high-level view if your workload is stalling due to waiting on memory: https://stackoverflow.com/questions/22165299/what-are-stalle.... However it won't tell you exactly where the problem is, just that there is a problem. You can do `perf record` on your process, and then running `perf report` on the generated data. You'll see what functions and what lines/instructions are taking the most time. Most of the time it will be pretty obvious that it's a memory bottleneck because it will be some kind of assignment or lookup.

If you're using an intel processor, VTune is extremely detailed. Here's a nice article from Intel on using it: https://www.intel.com/content/www/us/en/docs/vtune-profiler/... . You'll see one of the tables in the articles lists functions as "memory bound" - most time is spent waiting on memory, as opposed to executing computations.

khold_stare··on TinyLetter shut down by Mailchimp, so I built the letterdrop
And the code is godawful. Just look at this mess for internationalization: https://github.com/i365dev/LetterDrop/blob/main/app%2Fsrc%2F... . The code is unmaintainable by a human - there is a ton of unnecessary duplication, a gigantic html string instead of something like tsx, etc etc. I don't know how the OP can trust this output - I certainly don't.
khold_stare··on The UK's Controversial Online Safety Act Is Now Law
To reiterate the other comments - 15 minute cities are about _adding_ things so _more is accessible_ within a 15 minute travel time, such as stores, schools, public transit etc. Nothing to do with restrictions. Check this podcast out for a thorough debunking of all the misinformation about 15 minute cities, including the "Oxford trial" which has absolutely nothing to do with 15 minute cities - https://youtu.be/VxQBCIvwIho?si=tTnQS78TyUpp4gv8
khold_stare··on USDC depegs as Circle confirms $3.3B stuck with Silicon Valley Bank
That is definitely not how USDC is set up. The creator takes 1 USD, and gives back 1 USDC and vice versa. In this case, some of the USD held at SVB disappeared, so Circle has less money for the USDC -> USD redemptions. There needs to be a 1:1 backing, otherwise a stable coin is just smoke and mirrors.
khold_stare··on USDC depegs as Circle confirms $3.3B stuck with Silicon Valley Bank
This makes no sense. Circle's holdings are backing USDC. They can't use the money backing other USDC to buy more USDC. That's just market manipulation.
khold_stare··on NYSE Tuesday opening mayhem traced to a staffer who left a backup system running
Yes! I almost forgot about market orders because trading firms never use market orders for this exact reason - you have no control over the price if things go bad. Most flash crashes are exacerbated by runaway market orders and stop orders for example.

A buy market order would try to match with the "best price" which in a deeply crossed book would mean matching with a really low priced sell order. Exchanges match orders in price-time priority. Similar is true for a market sell order - would match at an extreme high price.

Besides the midpoint of the order book, another metric for a "current price of the stock" people use, is the "last trade price". In the situation above you would get "swings" in the price because market orders would be trading very high and very low if they alternate between buying and selling. The data structure on the exchange itself isn't "swinging", it's just the overlapping region being slowly eroded by market orders. The "last trade price" metric looks really insane in this situation.

khold_stare··on NYSE Tuesday opening mayhem traced to a staffer who left a backup system running
Yes. In my reply to the first comment I mentioned setting the opening price is "more complicated". Every exchange has their own system for the opening auction which you buy into when you list with a particular exchange. Most exchanges have an algorithmic way of calculating the price. For NYSE, it's again more historical. A Designated Market Maker (DMM) for a stock technically determines the opening price. There is a person physically on the NYSE trading floor who represents the DMM firm who technically opens the different stocks. They have a weird custom keyboard from NYSE for this purpose...

The price is usually calculated algorithmically by the DMM firm and sent to the person at NYSE to approve. Pretty arcane. Also somewhat shady, as the DMM firm can be and is part of the auction themselves. DMM firms can analyze the order book to see what the imbalance is in the overlapping region, and place an order of their own to correct the imbalance and then set the opening price. I can see how one can profit from this in certain situations

khold_stare··on NYSE Tuesday opening mayhem traced to a staffer who left a backup system running
Worked in HFT for a few years. The reason why most markets are not open 24 hours is more human, and just historical - aligned with people's 9-5 workday. There are also pre open and post close sessions of trading but it's much less liquid. Futures markets are open almost 24 hours. Even there, it's down for some time daily. Personally I think it's actually inertia that keeps existing markets this way - the systems of the exchanges and participants were designed with the assumption that they will have daily downtime, so it's hard to change. It's also dependant on how banking and settlement works - a lot of stuff happens after the trading ends. Batch processes run as different institutions settle their trades between each other, etc etc.

Now, as a result, there needs to be a way to set the opening price and closing price, like a bootstrap process. A smaller version of this process actually happens every time a stock gets halted and resumed.

An exchange has an order book - orders of things people want to buy and sell at different prices. During normal operation the buy and sell orders don't overlap in the order book - if two people want to buy and sell at the same overlapping price, they just get matched by the exchange at that moment. Unmatched orders stay in the order book data structure until a matching order comes along. The "price" you see in charts is just the midpoint between the highest buy and lowest sell price in the order book.

Now, if the order book is empty, what the heck is the price? That's what the opening auction needs to solve. The way it works is that people can start placing orders ahead of the opening bell, but they won't get matched until the open. So before the open, the order book is getting filled with orders, but crucially the _orders will overlap_. This "crossed" order book is a no no during normal trading, but ok before the opening auction. When the auction comes, a price is picked which maximizes the amount of orders filled (it's more nuanced than that, but bear with me). Imagine you pick a price in the overlapping region of the order book - every buy order that has a higher price than that will match with every sell orders that has a price lower than that. They will get matched and executed at the opening price, and BAM, you have an uncrossed order book, full of orders.

If the auction doesn't happen, and you just open the stock, then all hell breaks loose. Many things can go wrong here. Firms connected to the exchange may have code that assumes a book is not crossed (or at least not as crossed as it would be during an auction) causing wild behavior. The exchange itself could start matching orders haphazardly in the overlapping region, causing those "price swings" that the article talked about.

Can't imagine the panic that day haha.

khold_stare··on A chill driving game with procedurally generate scenic landscapes
Why not both? Have a free version and a paid version with more features/terrains/cars etc.
khold_stare··on What to know about the stock market (2007)
Really great article! Very well explained.

One small inaccuracy is the claim that there is only one place for each stock. That has not been true for many years. In the US that was changed by https://en.wikipedia.org/wiki/Regulation_NMS . NASDAQ is the primary listing exchange for MSFT, which means they will hold the opening and closing auctions, but it can be traded on any equities exchange, NYSE, IEX, BATS, EDGE-A, EDGE-X, you name it. RegNMS also has rules that if there is a better price at another exchange, the order must be routed there. This establishes the "NBBO" - National Best Bid and Offer, so in a way there is always one best bid and one best ask, but it's an aggregate over all the exchanges.

khold_stare··on What to know about the stock market (2007)
I greatly enjoy Michael Lewis and his books, but Flash boys was extremely inaccurate, full of factual errors. I've worked in the finance industry, in HFT at one of the firms mentioned in the book. I joined around the time Flash Boys came out, and it was required reading in the firm. Here are some points:

- Michael Lewis really only got one side of the story - that of Brad Katsuyama, who had a vested interest in casting HFT players in a bad light to promote his own business - building the new exchange IEX.

- Brad also blamed HFTs for systems at RBC failing to make massive trades like they used to. There was nothing nefarious here - RBC had just fallen behind the time in technology, like trying to send a Fax in a world where everyone already uses Email. If Brad, or RBC, or RBC software engineers picked up the phone and called any of the exchanges, they would probably gladly update them on the industry and save them all the work of re-discovering it themselves.

- The claims about front-running are completely false. Front running would mean that a market maker somehow knows someone's orders at two different exchanges and somehow is able to "get in front of the line" or even know that those orders belong to the same person. This would mean the exchanges leak information or allow certain users "ahead of the queue". None of this is true. What Michael Lewis called front-running, was HFT firms reducing their risk on other exchanges when they would get traded against on one exchange. They did this without any knowledge that Brad Katsuyama was on the other end, or that he was just late trying to make the same trade at another exchange at a later time. There are no guarantees that you can make the same trade at different exchanges - the same rules apply to everybody.

- Unsurprisingly, IEX as an exchange is no different from others, in that they need market makers (a.k.a. HFTs) to provide liquidity on their exchange. I wrote the code for the FIX gateways to connect our firm to IEX, and it was all business as usual.

khold_stare··on Faster Integer Parsing
Author of the article here - I completely agree. This text parsing problem came up because I was lamenting how many cycles were wasted in text processing. At my current job a text-based protocol from a 3rd party means around 80% of CPU time for the entire application is spent parsing and rendering text just for the protocol. JSON and HTTP come to mind too.

The human readability argument doesn't really hold any water because if you have a structured description of a protocol (e.g. a C struct), you can always write simple tools to inspect the protocol and make it just as humanly readable as JSON is. This is even easier if a language has reflection to generate all this code.

khold_stare··on Faster Integer Parsing
The problem with that instruction is that to do 4 at a time you would have to multiply by 1, 10, 100 and 1000 respectively. The last multiplier does not fit in a byte.
khold_stare··on Show HN: Faster Integer Parsing
Hey, thank you so much for reading! I will try to post more often now that we're all in a lockdown :)
khold_stare··on Perils of Constructors
I completely agree with most of the post. In C++ I use the static factory method "trick" mentioned in the post, when constructing subobjects may throw or result in some kind of error. Throwing from the middle of a constructor in C++ is a quagmire, so it's best not to do it. Bonus, you can mark the constructor and factory functions noexcept.

The part I disagree with relates to "relying on the optimizer for placement". Even in C++ using the above factory pattern, you are returning the constructed object from a function - and there is no problem if it is ultimately part of some larger object. The C++ standard specifies copy-elision very precisely so you don't have to hope the optimizer does it - it is required to. To demonstrate you can do stuff like this even if you object contains non-moveable members, like std::mutex

  class Foo
  {
  private:
    std::mutex mutex_;
    SomeComplexSubObject sub_;

    Foo(SomeComplexSubObject sub) noexcept
      : sub_{std::move(sub)}
    { }

  public:
    static std::optional<Foo> make(SomeParams params) noexcept
    {
      try {
        return Foo{SomeComplexSubObject{params}};
      }
      catch (std::exception const& e) {
        return std::nullopt;
      }
    }
  };
I think Rust can also specify something like this (ie. "copy-elision") as part of its unwritten spec. Anyway, great article! :)
khold_stare··on Money Machines – An Interview with an Anonymous Algorithmic Trader
This particular desk wasn't perfect - it had its ups and downs (there were definitely days where money was lost). Overall though it was profitable.
khold_stare··on Money Machines – An Interview with an Anonymous Algorithmic Trader
Sure! I'll just ramble a bit about HFTs.

I'd say starting a "pure" HFT firm is incredibly hard nowadays. There's a big upfront investment and huge operating costs, and there's a lot of consolidation happening in the industry.

In general, most hardware and software is tailored to high-throughput, and a huge part of the effort of HFT is fighting all that to prioritize latency. If you want to compete with the very best firms, that means renting rackspace in a colocation with the exchanges, overclocked CPUs, expensive network cards, FPGAs, paying out the nose for the most accurate market-data feeds, and many order-entry connections. Then you have to tweak the BIOS, kernel settings, isolate your processes on cores, write your own userspace networking stack etc. etc. etc. On top of that if you want to trade between different colocations, you might need a network of microwave towers because fiber is too slow (light travels about 2/3 slower in fiber because it effectively "bounces" along the fiber). At the end of the day though, if your algorithm or strategy doesn't work, you won't make any money - speed is only a part of it. At the previous firm, we had a market making desk that was very profitable, but was quite "slow" by HFT standards (triple digit microseconds vs sub-microsecond response times). You still need to be smart about it.

Having said all that, I think HFT gets a bad rap, about being a waste of resources/talent, and somehow "stealing" from the common man. The truth is, they are only "stealing" from each other - they compete to remove the tiniest inefficiencies in pricing. They ensure the cost of trading is actually as low as it can possibly be. By themselves they don't have enough capital to move the market in any meaningful way. In fact, most flash crashes occur when HFT firms step out of the way! They move out of the way of huge market movements because they can't cushion the blow without taking an unnecessary risk as a business. It's like asking your plumber to fix your sink while your house is on fire. Market orders, stop orders and panic are most of the problem when it comes to flash crashes. PSA: Please use limit orders :)

I might ruffle some feathers with the comments, but I think overall HFTs aren't the bogeyman most people think them to be. Sure there are some bad apples, but that's true of any industry, and it comes down to the people - not the system itself.

khold_stare··on Money Machines – An Interview with an Anonymous Algorithmic Trader
I can give some advice, but you should take it with a grain of salt :) I have been more of an infrastructure guy, and building the platforms with quants/traders, and not really trading myself. I am also more familiar with HFT trades overall.

I think you're on the right track regarding value investment, if you're thinking about it long-term, and it's for personal investments. Passive index funds like SPY are the best bet for most people. Finding companies or following trends you in particular have some insight on can also help. Things like "having worked in industry X, and having read their whitepapers, this new company is clearly overbought and is all marketing hype".

If you want to get more analytical, look at portfolio theory, different hedging strategies, and try and find "alpha" - roughly meaning the extra factors explaining the price of an instrument that gives you an edge over others. Check out Quantopian - they have some nice articles too. The key is coming up with a model that accurately captures the risk of your assets which would allow you to properly allocate your money amongst them.

Page 1 of 2Next →