News for hackers. Stuff that matters.
Re:Faster and simpler with the command line: deep-comparing ... by jb3689 on Thursday December 06, 2018 @10:18AM (#18618650)
It's worth mentioning that there are much faster JSON parsing libraries than the default in Ruby stdlib. I still don't think Ruby is the best choice for doing raw JSON parsing. Last time I had to care about JSON speed we were transforming billions of events and the Ruby JSON lib was becoming a bottleneck
Re:Faster and simpler with the command line: deep-comparing ... by paulddraper on Thursday December 06, 2018 @11:48AM (#18619643)
> It's worth mentioning that there are much faster JSON parsing libraries than the default in Ruby stdlib.

I am on the edge of my seat now.

Would you mind listing which libraries are much (say, an order of magnitude) faster?

Re:Faster and simpler with the command line: deep-comparing ... by rajangdavis on Friday December 07, 2018 @02:20AM (#18625738)
Don't think it's an order of magnitude faster, but oj is supposed to be the standard for Ruby.

https://github.com/ohler55/oj

Re:Faster and simpler with the command line: deep-comparing ... by baldeagle on Thursday December 06, 2018 @10:39AM (#18618892)
What do you think is the best way to do deep JSON comparisons? We work with 2GB JSONs all day, and it is super annoying how long they take to process.
Re:Faster and simpler with the command line: deep-comparing ... by vidarh on Thursday December 06, 2018 @11:02AM (#18619129)
Not parse them into a tree, to start with.

Use a streaming JSON parser, and compare them token by token unless/until they diverge, at which point you take whatever actual suitable to identify the delta.

Parsing it into a tree may be necessary if you want to do more complex comparisons (such as sorting child objects etc.), but even then depending on your need you may well be better off storing offsets into the file depending on your requirements.

https://github.com/lloyd/yajl is an example of a streaming JSON parser (caveat: I've not benchmarked it at all), but JSON is simple enough to write one specifically to handle two streams.

Re:Faster and simpler with the command line: deep-comparing ... by proyb2 on Thursday December 06, 2018 @11:15AM (#18619270)
I believe this comparison benchmark could be useful for you and you can expand further with more tests. Although I got downvoted for sharing a link.

https://github.com/kostya/benchmarks/blob/master/README.md

Re:Faster and simpler with the command line: deep-comparing ... by vidarh on Thursday December 06, 2018 @11:31AM (#18619441)
That still parses into a tree.
Re:Faster and simpler with the command line: deep-comparing ... by nicoburns on Thursday December 06, 2018 @11:43AM (#18619586)
Rust is absolutely wonderful for tasks like this. They don't hit any of the cases where Rust's ownership can make things tricky. And the serde library makes deserializing JSON a piece of cake.

You end up with code which looks pretty similar to the equivalent JavaScript or Python code, but performs much faster (10x, 100x or even 1000x faster).

Re:Faster and simpler with the command line: deep-comparing ... by nicoburns on Thursday December 06, 2018 @11:44AM (#18619594)
There's also pikkr (https://github.com/pikkr/pikkr) if you need really really fast JSON parsing.
Re:Faster and simpler with the command line: deep-comparing ... by Filligree on Thursday December 06, 2018 @10:47AM (#18618982)
Start with a compiled language, I guess? I don't operate on anywhere near that scale, but json-rust reaches 400 MB/s for me.

It doesn't parallelize, and you'd need memory enough for the entire structure, but of course Rust doesn't have GC overhead. You could trivially parse both files in parallel, at least.

Re:Faster and simpler with the command line: deep-comparing ... by theamk on Thursday December 06, 2018 @11:35AM (#18619482)
(1) Try a language with fast allocations (C, C++, Rust, maybe Go or Java) -- anything except Python or Ruby

or

(2) Try using streaming API (I don't know Ruby, but quick google found https://github.com/dgraham/json-stream ). Note that this method will require you to massively restructure your program -- you want to avoid having all of the data in memory at once.

The streaming API might work better with jq-based preprocessing -- for example, if you want to compare two unsorted sets, it may be faster to sort them using jq, then compare line-by-line using streaming API.

Re:Faster and simpler with the command line: deep-comparing ... by dith3r on Thursday December 06, 2018 @12:02PM (#18619763)
Python is fast at parsing JSON, Go had hard time to match parsing speed of it. Additionally you have PyPy to help.
Re:Faster and simpler with the command line: deep-comparing ... by mattbillenstein on Thursday December 06, 2018 @12:20PM (#18620004)
Re:Faster and simpler with the command line: deep-comparing ... by Filligree on Friday December 07, 2018 @09:59AM (#18628161)
Python is fast at doing anything that doesn't involve running Python.

That's an important caveat. Python's C JSON parser library is super-fast, but if you want to use the data for anything but a simple equality check afterwards, it'll be slow as molasses.

Or you'll write a C extension for it...

Re:Faster and simpler with the command line: deep-comparing ... by gyrgtyn on Thursday December 06, 2018 @11:15AM (#18619271)
nodejs comes to mind!