Opening a list moves the feed list's highlight instead of redrawing it (#490)

Profiled on production's lists at an iPhone 13's size with the CPU slowed
4x, opening four lists twice: selectFeed rebuilt every feed row (about
300 ms of the run) only to move .sel and aria-current, and dateOf made a
new Intl.DateTimeFormat for every row through toLocaleDateString with
options (about 155 ms). With markSelected and one shared formatter the
run's CPU time fell from 2.3-2.5 s to 1.25-1.65 s; dateOf from 157 ms to
12 ms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RqkrVBuJRne2JAhFpaDV2U
This commit is contained in:
2026-11-22 11:26:09 -05:00
parent 33b595973a
commit f633f3d692
3 changed files with 14 additions and 2 deletions

View File

@@ -204,7 +204,16 @@ function renderFeeds(){
function selectFeed(id: string){
S.feed=id; S.offset=0; S.sel=null; S.q=''; S.season=''; sortPicked=false; $<HTMLInputElement>('#epSearch').value='';
try{ localStorage.setItem('ipx.feed',id); }catch{}
renderFeeds(); renderFeed(); loadEntries();
markSelected(); renderFeed(); loadEntries();
}
/// The highlight moved to the feed now open. Rebuilding every row for it, as selecting once did,
/// was a third of a list's drawing time on a phone.
function markSelected(){
for(const el of $$<HTMLElement>('#feedlist [data-id]')){
const on=el.dataset.id===S.feed;
el.classList.toggle('sel',on);
if(on) el.setAttribute('aria-current','page'); else el.removeAttribute('aria-current');
}
}
/// A failing feed's error, in plain words with something to do about it, once `failing` is

View File

@@ -302,7 +302,9 @@ const ago = (t: number|null) => {
if(d<2592000) return Math.round(d/86400)+'d ago';
return new Date(t*1000).toLocaleDateString(undefined,{month:'short',day:'numeric',year:'numeric'});
};
const dateOf = (t: number|null) => t?new Date(t*1000).toLocaleDateString(undefined,{month:'short',day:'numeric',year:'numeric'}):'';
// One formatter: toLocaleDateString with options makes a new one each call, every row of a list.
const DATE_FMT = new Intl.DateTimeFormat(undefined,{month:'short',day:'numeric',year:'numeric'});
const dateOf = (t: number|null) => t?DATE_FMT.format(t*1000):'';
// A podcast episode is tens of MB, an article's image a few KB: whole MB made the small ones "0 MB".
const mb = (n: number|null) => !n?'' : n<1048576?Math.max(1,Math.round(n/1024))+' KB'
: n<1073741824?Math.round(n/1048576)+' MB' : (n/1073741824).toFixed(1)+' GB';