perf(xtream): Decode the channel list from the stream into typed rows #34
Loading…
Reference in a new issue
No description provided.
Delete branch "perf/typed-stream-decode"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What was wrong
XtreamClient.liveChannelsread the wholeget_live_streamsbody into one String (7.9 MB for the 23,960 channels of the pool, our IPTV pool server). It then calledparseToJsonElement, which builds a tree of every row and all 15 of its fields, before mapping the 8 fields the app reads. On a low-RAM TV that String and the tree are alive at the same time.What changed
XtreamRows.ktaddsXtreamStreamwith only the fields the app reads (stream_id,name,stream_icon,epg_channel_id,category_id,tv_archive,tv_archive_duration,num) pluspool_event, the live game a Live Now channel carries.XtreamClient.ktdecodes the list straight from the response stream into it withdecodeFromStream, skipping other fields, then maps each row toLiveChannelas before.LenientTextreads those fields as text whether the provider sends"187"or187, matching the oldJsonElement?.str()helper. An object or array in one of them reads as null.pool_eventstays aJsonElement, soPoolSignals.parseEventis unchanged.liveCategoriesdecodes intoXtreamCategorythe same way.nullitems are skipped and a UTF-8 byte order mark is ignored. One difference: an array item that is a number or a string now fails the whole list, where the old parse skipped it. No panel I know of sends one.Verified
testDebugUnitTest(574 tests, 9 new inXtreamListDecodeTest.kt: strings versus numbers, odd values, unknown and nested fields, pool events, bodies that give an empty list, bodies that throw, null items and a byte order mark, escapes and non-ASCII names, categories),lintDebugandassembleDebugpass.LiveNowEventsTestpasses unchanged. I checked the error cases against the old parse with a throwaway test.The real list for the tv3 test login (23,960 channels, saved locally and deleted afterwards), parsed by the old code and the new code in a throwaway JVM test with no network: the two lists were equal field for field, with 34 pool events. Median of 5 runs after warm-up: old 29 ms and 123 MB allocated, new 27 ms and 53 MB.
LiveWireTV_API34 emulator with the tv3 login, with temporary logging (removed before commit), 5 cold starts each. Time and runtime allocation for the full list call, download included:
mainHome's lists and now-playing, and the Guide's channel count and Live Now game blocks, looked the same as on
main, including after the error-handling fix. I haven't measured on a TV.