xyncro / chiron

JSON for F#
https://xyncro.tech/chiron
MIT License
173 stars 41 forks source link

Slow when rendering long strings #64

Closed ZjMNZHgG5jMXw closed 7 years ago

ZjMNZHgG5jMXw commented 8 years ago

I'm trying to render long strings as json. A (minimal) example would is String.replicate 30000 "a" |> Json.serialize |> Json.format |> printfn "%s" The F# program (or script) with Chiron is taking much more time to render than comparable programs in, e.g., Go.

Is there anything that I could change, like maybe a more efficient string implementation, to improve the situation?

Thanks!

kolektiv commented 8 years ago

Hmmmm. I would think that I'd have to start by benchmarking - String.replicate, and printfn are potentially both pretty slow, even aside from Chiron! Being honest, Chiron is probably not the highest performing JSON lib - it's more focused on power and flexibility. That said, it's always worth looking, so if we can get something representative benchmarked I'll take a look!

ZjMNZHgG5jMXw commented 8 years ago

I suspected something else in the chain as well, for instance, printfn, but it showed that String.replicate 30000 "a" |> printfn "%s" was much faster.

kolektiv commented 8 years ago

Hmnmm, we'll definitely need to get some numbers and profiling set up to see where potential hotspots are. I'm fairly snowed under for the next week or two, but will hopefully be able to give it some attention after that.

ZjMNZHgG5jMXw commented 8 years ago

I'd guess that it is the escaping. Any data of similar quantities go through the Json.serialize |> Json.format chain much quicker.

neoeinstein commented 7 years ago

I've been pinged by this issue now as well. I will be taking a swing at a PR today. The hot spot is definitely in the escaping function.

kolektiv commented 7 years ago

Yes, I can certainly imagine. I've not had the bandwidth to look at that function, but I can certainly imagine a less functional, but more efficient mutating approach! A PR will be happily received 😄