PMJSON icon indicating copy to clipboard operation
PMJSON copied to clipboard

Consider adding JSONCompatible protocol

Open lilyball opened this issue 7 years ago • 2 comments

We should consider having a JSONCompatible protocol that is conformed to by things like String, Int, etc, as a replacement for the family of JSON.init(_:) initializers. We could then have a single JSON.init(_:) initializer that is generic using this protocol.

The goal here is to sidestep the type-checking complexity issue when using a bunch of JSON(foo) calls in the same expression.

We should also do some microbenchmarks on performance, because generics are implemented using a dictionary-passing mechanism, and we want to make sure that switching to a single generic initializer doesn't have a significant effect on how long it takes to construct these.

Note that if we do this we might have to bump the major version in order to mark the existing JSON.init(_:) methods as unavailable. The problem is that just leaving them as deprecated is still likely going to incur the type-checking penalty. But we should test.

lilyball avatar Feb 23 '18 21:02 lilyball

We could also investigate switching the ExpressibleByDictionaryLiteral and ExpressibleByArrayLiteral implementations over to using JSONCompatible existentials, so that way you can mix non-JSON values into the literals, but if so we definitely need to microbenchmark it because this will wrap even JSON values up in protocol existentials which seems like a lot of unnecessary work.

lilyball avatar Feb 23 '18 21:02 lilyball

I'm going to push this off as well. It's not clear how much of a win there is with this.

lilyball avatar Nov 15 '19 03:11 lilyball