Closed medigor closed 3 years ago
Changing the above to
let getStringFromObj(v)=
let r = v.GetType().GetCustomAttributes(false)
|> Seq.exists (function
| :? Core.StringEnumAttribute -> true
| _ -> false)
if r then stringEnum v else v.ToString()
let cssProp = cssPropsCache.GetOrAdd(value,System.Func<obj,string>(getStringFromObj))
escapeHtml html cssProp
leads to the following results: https://github.com/delneg/fable-react/blob/fix/ssr-sample/docs/server-side-rendering.md#run-simple-benchmark-test-in-sample-app
Before: [Single thread] 72367ms 4421.905req/s [16 tasks] Total: 14685ms Memory footprint: 46.992MB Requests/sec: 21790.943
After: [Single thread] 20842ms 15353.613req/s [16 tasks] Total: 5610ms Memory footprint: 46.934MB Requests/sec: 57040.998
@alfonsogarciacaro Please take a look as this means a huge perfomance boost
Awesome, thank you both for spotting and fixing this! I will push a new release with the change :+1:
Fixed by #216
https://github.com/fable-compiler/fable-react/blob/d813cee23227158b0be9af25fcc1f890253806f4/src/Fable.ReactServer.fs#L44-L51
instead:
ConcurrentDictionary<TKey,TValue>.GetOrAdd(TKey, TValue)
should use:ConcurrentDictionary<TKey,TValue>.GetOrAdd(TKey, Func<TKey,TValue>)