threepointone / bs-nice

css-in-reason
180 stars 14 forks source link

Change string_of_float/string_of_whatever to js string interpolation #13

Closed wokalski closed 6 years ago

wokalski commented 6 years ago

Js string interpolation is much much faster than string_of_whatever/Printf built ins.

threepointone commented 6 years ago

It’s not so much faster from the look of it? https://github.com/threepointone/bs-nice/issues/3 And I want to keep this as pure reason, will it affect how I do builds for native?

thangngoc89 commented 6 years ago

@threepointone you currently can't use JS API for native build.

wokalski commented 6 years ago

yes, it won't work on "native" (as in if you compile it down to native machine code). It is a tradeoff however, it's easily swappable. You might as well use functors to make it backend-dependent. In any case string_of_float prints 100 as "100." so that's a possible bug (i.e. 100.% is invalid, right?) and Printf is quite heavy.

It's up to you, and ultimately the perf hit is not huge but printf is definitely a big runtime/size cost (it's a complicated beast). So I'd opt in for either string_of_x or js string interpolation. It depends on your future plans and how really feasible it is that it'll run on native any time soon.

threepointone commented 6 years ago

I'm going to punt on 'pure' native for now, and revisit later. so you're saying I can basically replace Printf.sprintf("%f", x) with {j|${x}|j}?

threepointone commented 6 years ago

replaced printf with string interpolation