Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@biplavbarua
Copy link

Context

Fixes #2840.

Problem

The list property in Clock/settings.swift was reading/writing to UserDefaults (JSON encode/decode) on every keystroke in the settings UI. This caused performance issues and prevented users from typing custom formats smoothly.

Solution

  • Implemented a local cachedList in Settings.
  • init() : Loads from Store once.
  • get : Reads from memory (instant).
  • set : Updates memory and persists to Store.

@exelban
Copy link
Owner

exelban commented Dec 15, 2025

how it fixes #2840?

@biplavbarua
Copy link
Author

The issue in #2840 (unable to set time format) happens because the previous list implementation triggered a full JSON decode & disk read on every single keystroke.
This heavy operation caused the NSTextField binding to lag or reset mid-typing, effectively rejecting the user's input before they could finish.
By checking cachedList (memory) instead of Store (disk) for the getter, the UI binding remains stable and responsive, allowing the user to type the full format string without interruption. The save() to disk only happens after the change is committed.

@exelban
Copy link
Owner

exelban commented Dec 18, 2025

it does not, since Store has internal cache, so what you do is basically duplicate the login inside Store. But again, how that fixes #2840?

@biplavbarua
Copy link
Author

Hi @exelban, thanks for checking this!

You are completely right that Store caches the raw Data, so we aren't hitting the disk. However, the performance bottleneck here isn't the disk I/O, but the JSON Decoding.
Without cachedList, the list getter calls JSONDecoder().decode(...) every single time it's accessed. Since list is used by numberOfRows and viewFor in the TableView, this forces a full JSON decode operation for every frame/cell render, which causes the specific UI stutter/lag reported in #2840 when typing or scrolling.

My change ensures we decode the JSON only once (on init/set) and serve the ready-to-use object from memory thereafter.

@exelban
Copy link
Owner

exelban commented Dec 18, 2025

Oh, yeah, I see the problem with json. But still, how it fixes #2840?
Problem there that settings does not appear because the widget is not active, how cache will solve that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Setting Timeformat

2 participants