4 ms·
Storage of data that is usually but not ALWAYS in a shorter range is a complicated problem if you don't just throw more RAM at it. Perhaps a CPU built around a
by bombcar 6y ago
Storage of data that is usually but not ALWAYS in a shorter range is a complicated problem if you don't just throw more RAM at it.
Perhaps a CPU built around a base numeric type more like UTF-8 would be useful? Short values would take only a smaller amount of RAM but longer values would still work?
I suspect in the era of 64 bit CPUs that isn't much of an advantage anymore.
- goalieca 6y agoProcessors have had BCD (binary coded decimal) instructions since the earliest 8-bit micros. They usually deal with 0-99 and then you have to add digit by digit but it can handle carry propagation.
- greenyoda 6y agoMuch earlier than that. The IBM/360 architecture had instructions for doing arithmetic with BCD numbers (packed and zoned decimal formats) in the mid-1960s. I think earlier IBM architectures had them too. COBOL natively supports that datatype, so did PL/I. After all, the biggest customers for mainframes were banks, insurance companies, the IRS, etc. that dealt with large sums of money and needed their accounts to be accurate to the nearest cent. Dealing with very large integer values is a problem that was solved a long, long time ago.
- Rebelgecko 6y agoWhen I worked on a semi-similar problem (a realtime-ish feed with lots of numbers), we found that it was better to just eat the extra RAM costs. Once you have variable width values, it gets much more expensive to answer questions like "Here's a file with every stock price, we know that Berkshire is the 1,000th one in the list, what is their current price?" Instead of being able to jump straight to the relevant bytes, you end up needing to parse (potentially) the entire file. Even with better CPU support for variable integer sizes, you're still essentially turning an O(1) operation into one that is O(N)
- bombcar 6y agoI wonder if a CPU could do something like have 9-bit bytes internally that would allow you to quickly jump over a list like that (use the 9th bit to indicate the first of a multi-byte sequence or something). You'd need dedicated hardware to make it as fast as 1000xRecordsize, though.
- firethief 6y agoThat's the typical approach to varints except optimized for hardware with 9-bit bytes. It's not the kind of thing that dedicated instructions can make faster, or we'd be using them all the time.
- Const-me 6y agoYou don’t really need dedicated instructions for them. Programmers can do that today, and many decades in the past too, with software. For example, Java has BigInteger in the standard library for decades now. The reason they did not is less about memory (it would save memory on average, many numbers in that system need less than 4 bytes) more about CPU time. That system is likely very old, older than wide adoption of 64-bit processors. The reason we don’t often use variable-length integers now, memory and storage are cheap. For new software people simply use 64 or 128 bit integers. Still, variable-length integers are widely used when storage or bandwidth matters. They are all over binary network protocols, multimedia containers, and media codecs.
- bluedino 6y agoNASDAQ programmer, somewhere around 1982: "What kind of company would let their stock get over $400,000?"
- jschwartzi 6y ago"That's more money than my boss makes in a year."
- Kranar 6y agoExchanges compete on speed. If exchange A delivers data in half the packet size and requires smaller word sizes to operate on and exchange B decides it's okay to double the packet size and requires twice the word size... exchange A gets the trade and exchange B is left holding the bag. Back in the day the major exchanges, NASDAQ and NYSE in the U.S. and the TSX in Canada used to operate as a mafia with a monopoly on the stock market. Entire exchanges came into being strictly on the basis that they had lower bandwidth requirements and operated faster, such as BATS and DirectEdge (which ended up merging), CHI-X, Omega, and a host of competition emerged to actually focus on technology. They ended up taking a large chunk of market share away from the major exchanges. Now NASDAQ and NYSE have since caught up, and in some ways they did so by buying out these competitors. Modulo some embarrassing glitches over the past few years, the major exchanges need to continue supporting their legacy systems for major institutions who are very slow and hesitant to upgrade any aspect of their technology. NASDAQ has a more advanced and modern data feed and that feed doesn't have this issue, BRK.A is being reported properly at its price as we speak, but that feed isn't widely adopted except by firms that generally build their own technology and have a team that can keep their tech up to date. The feed that has this issue is like 20 years old now and rarely gets updates, and many firms like to keep it that way.
- xeeeeeeeeeeenu 6y ago>Perhaps a CPU built around a base numeric type more like UTF-8 would be useful? Short values would take only a smaller amount of RAM but longer values would still work? https://en.wikipedia.org/wiki/Carry_flag https://en.wikipedia.org/wiki/Carry_flag