by lpcvoid · 7y ago · 0 comments
https://microsoft.github.io/language-server-protocol/specifi...
But what I would care about is that it's easy to create a protocol specification and to generate most of the boilerplate code out of it - so that the schema gets automatically verified and that developers can focus on building their application logic instead of getting the serialization right. That can be done with JSON too (e.g. with json-schema or by generating code out of typescript definitions). However I haven't yet checked whether LSP and the debug protocol make use of this.
JavaScript developers really do hold skewed ideas about what kinds of things are useful and worth the overhead that they incur.
Binary protocols are easier than JSON, to me, and to most people I would say, who have actually implemented a binary protocol or wrote code to read or write binary files.
JSON isn't really anything to do with JavaScript any more. It's a format that's used with practically every language. Any experienced developer should know that.
JSON has a lot to do with JavaScript. I don't know why you think JavaScript doesn't have anything to do with JSON. JSON and JavaScript are used together every day.
Especially not with broad vagaries like "Binary protocols are easier than JSON".
A computer program (an IDE in this scenario) talking to another computer program (the debugger) simply does not need to use JSON! By choosing to use JSON, a choice was made to make the protocol far more inefficient than it needed to be.
The result will be a slower than necessary debugging experience for all who use it. Debuggers already consume enough developer time per day! Choices should be made to make developer lives better, not worse.
You're speaking super hand wavy though. What specific protocol is better than JSON? I'm sure there are plenty, but that's not the point.
The point is, if it's not as common as JSON then it can hardly be considered easier, can it? If I have to write a implementation of X protocol just to work with this DAP or LSP, is that really easier?
Imo, commonality is hugely important when you're trying to work with every editor and every language (that editors are written in) out there.
I'm not saying there isn't a binary protocol that would be in every language out there. However JSON basically is, at the very least. So lets talk apples to apples about what you think is better, because "Binary protocols" is the vague sense are not even remotely as common and widely supported as JSON.
Don't get me wrong, I sort of hate JSON. Yet for many applications, especially those seeking compliance with everything under the sun, it has merit.
You're describing easier for a computer, which isn't really relevant. For a developer, parsing JSON is clearly easier than parsing a binary format. For effectively every major language nowadays, it's a single function call, and you're done, it's hard to beat that.
In practice, sending & parsing JSON instead of a binary format is not going to make your debugging experience here any _noticeably_ slower (if you have a DAP case where it does, I'd love to see it) and it is going to make development quicker & easier, and make the traffic inflight easier to debug too.
It's a tradeoff of course, but for most cases it's worthwhile.
Does not mean anything.
Who defines the "difficulty" of a protocol based on serialization?!
What is that even supposed to mean?
The protocol can be hard to understand, it can make unreasonable demands of users, it can have a ton of bloat or complex backwards compatibility rules.
But the serialization method literally orthogonal to complexity of the protocol itself
Implementing a protobuf serializer or implementing a JSON serializer would be completely 100% outside of the scope of a protocol that uses either.
Doubly so when you're talking about JSON, which has serializers just about everywhere, so you can't even say "oh well the protocol is easy to understand but the serialization method is hard to implement".
If anything using a custom binary serialization implementation would be the worst of both worlds, now consumers have to implement custom serialization AND you have to solve all the issues other solutions did like endianness, backwards compatibility... not having gaping security vulnerabilities...
This is like saying a protocol is "difficult" because you used it over HTTP so now somehow it inherited the entire complexity of HTTP.
Their protocol's complexity isn't defined by it's serialization any more than it is by the transport they're using.
I won't even bother replying to the rest of that, just very vague handwavy rhetoric that's not saying anything much.
Can I use the protocol with simple command line tools or do I have to spend several hours coding up a protocol handler?
Will implementers be more or less likely to fuck up their implementation of a binary protocol?
How will you version the binary protocol? How will you maintain backwards compatibility?
Of course you do, something has to actually read the strings and parse them into JS data structures.
You don't need protobuf, you don't need json, you don't need any of these things that just add bloat and cost you performance.
Writing and reading binary is easy, and is FAR easier than JSON if you are using something like C.
Most languages have convenience methods for strings, yes, and those can be stacked on top of each other so that JSON libraries can be written, of course. Those libraries are FAR slower than just reading and writing bytes, and deserializing those bytes into structs or serializing those structs into a byte array, and the binary data is much smaller than a JSON document containing the same data would be.
People these days are acting like binary protocols are hard, or that they are suboptimal for one reason or another. I guarantee you that someone who was trying to find a bug in a JSON library will spend as much time or more than someone trying to find a similar bug in a method that reads or writes binary data, and at the end of it, the person who looked at the methods that handle binary data will FULLY understand what is happening in that code. The person debugging the JSON library will almost certainly not have a full understanding of the JSON library after finding and fixing a bug unless they wrote it to begin with.
It comes down to this - all computer programs do is process data. All UX problems, all usability problems, all computer problems boil down to problems transforming data. Transforming data is literally the only thing a computer can do. Any work spent writing code that does not directly solve the data transformation problem at hand is wasted time and work on the part of the developer. Any performance lost using code that does not directly solve the data transformation problem at hand is time away from the CPU for other tasks, time away from a consumer of that data, and so on. It adds up, and it adds up quickly.
I call them the peanut gallery and the best way to deal when them is to pat them on their head for being so smart, thank them for their opinion and ignore everything they said. Failure to mute them will derail any project lead by a junior dev who doesn’t get know how to deal with pot shots from the peanut gallery. The poor junior dev will actually listen to the worthless feedback and stall the project.
I’m sure the folks who worked on this protocol are rolling their eyes at this comment thread...
(yes, there are 3rd party libraries that provide some or all of the above, but they may not be applicable for a variety of reasons, including API stability, maintainability, compiler support, host/target OS support, tooling support, C language version support and a bunch of others)
Yeah more or less that's true, but in typed languages especially it's pretty inconvenient (unless you circumvent the type system or dump directly into a hash table, but that's usually bad).
> It's easy to debug
There are tons of corner cases re: parsing JSON [1]. Plus things like canonicalization and duplicate keys are pretty confounding.
> You also don’t have any overhead for parsing in JavaScript based editors like VSCode and Atom.
JSON isn't JavaScript and parsing it with `eval` is super bad practice. And there is indeed parsing overhead [2].
[1]: http://seriot.ch/parsing_json.php#4
[2]: https://github.com/msgpack/msgpack-javascript#benchmark
Given all the other constraints on the product, how does making a binary protocol fit in? What trade offs will be made if they used a binary protocol?
This is a move toward being able to debug programs on Azure with VSCode remotely.
There's a lot of talk about fast C++ JSON libraries and how they can parse 1GB of JSON per second, and that's a lot of data, for sure, if you only count the data that's wrapped up in JSON. 1GB of JSON data contains a lot of waste that is not even usable data, and that's before you consider the textual encoding of what may better be represented by binary data, which inflates the size of a JSON file even further than the JSON syntax itself does. A binary file that is read at 1GB per second would contain far, far more actual data, and binary files can be read and written much more quickly than 1GB/s.
I'm really starting to lose patience with all the JSON and web technologies that are finding their way into non-web use cases. using binary formats and simple programs to handle them is really, truly, easier to rationalize about, easier to maintain, easier to write, and easier to replace when the time comes.
1) Write a JSON library from scratch.
2) Write a method to handle a binary format from scratch.
3) Compare them.
I understand that you are likely relying on some JSON library or language feature, and I would argue that you will bear the weight of that all of that code the instant it has any problem, and that you bear the performance cost every time you use it. Maybe that library or language feature doesn't have any functionality bugs that you encounter; you will still pay for the loss in performance for as long as you use it.
Maybe this is acceptable. For me, if I'm writing a tool that either delivers a result that a human relies on, or is a tool that a human uses, I consider it immoral to waste that human's time without a very good reason.
I always try to avoid wasting my own time. Reasoning about code that reads and writes binary files is much easier for me than reasoning about an entire JSON library.
Desktop, laptop, and tablet CPUs are not getting faster overall. In fact, they're getting slower as cores are added to the silicon dies.
We've lived as developers for far too long under the performance gains provided by hardware advancement. Software has generally improved performance only when put on newer and faster hardware platforms. As a general rule, faster hardware platforms aren't a guarantee anymore. We may have more cores to run on, or more CPUs thrown at us to improve performance, yes. We can improve performance in other ways, with zero hardware cost. Avoiding JSON unless it is actually needed is one way we can reclaim performance from the debt of our previous decisions.