核心数据 - 我可以将计算值存储为持久属性吗?

发布于 2024-10-04 11:46:46 字数 905 浏览 7 评论 0原文

背景

  • 我有一个计算值存储在瞬态属性中。
  • 每次我的应用程序启动时,瞬态都需要更新。
  • 启动时间确实很慢(即10-15秒)
  • Instruments确认更新非常昂贵。

问题

可以将计算值存储在持久属性中吗?

我将使用 Martin Brugger 的从属属性 来保持计算值最新。

更多信息

我的计算值是数千个对象的持续时间:

Name                       Duration
Users                      70s            
    Proposal.doc           35s   
      12:32-12:32          5s   
      13:11-13:11          30s   
    Proposal2.doc          35s   
      14:32-14:32          15s   
      15:11-15:11          20s   
    ...thousands more objects...

我尝试过的

  • 我已经使用预取和setReturnsObjectsAsFaults:NO最大限度地减少了触发的故障数量,但它使用了负载的内存,但仍然需要很长时间。

  • 我已经使我的瞬态更新代码尽可能高效。

  • 我知道我可以在后台线程上获取并使用进度条,但我希望用户根本不必等待。

Background

  • I have a calculated value stored in a transient attribute.
  • Every time my app starts up, the transient needs to be updated.
  • Startup time is really slow (i.e. 10-15 seconds)
  • Instruments confirms the update is very expensive.

Question

Is it OK to store a calculated value in a persistent attribute?

I'd use Martin Brugger's Dependant Properties to keep the calculated value up to date.

More Information

My calculated value is the duration on thousands of objects:

Name                       Duration
Users                      70s            
    Proposal.doc           35s   
      12:32-12:32          5s   
      13:11-13:11          30s   
    Proposal2.doc          35s   
      14:32-14:32          15s   
      15:11-15:11          20s   
    ...thousands more objects...

What I've Tried

  • I've minimised the number of faults that are firing, using prefetching and setReturnsObjectsAsFaults:NO but it uses loads of memory and still takes ages.

  • I've made my transient updating code as efficient as I know how.

  • I know I could fetch on a background thread and use a progress bar, but I'd prefer the user to not have to wait at all.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梨涡少年 2024-10-11 11:46:46

我不确定我是否完全理解这个问题,但我认为您所问的问题的简单答案是“当然”。 :-)

拥有瞬态、实时计算的“currentTotalDuration”值和“cachedTotalDuration”属性没有任何问题。当“currentTotalDuration”更新后,扔到“cachedTotalDuration”中就完成了。对我来说,拥有一个持久缓存属性和一个仅在需要更新时才使用的“实时计算”瞬态值听起来完全合理。

我不熟悉 Martin Brugger 的从属属性,但听起来大部分艰苦的工作已经为您完成了。

我希望我回答了您实际提出的问题。 :-D

I'm not sure I fully understand the question, but the simple answer to what I think you're asking is "of course." :-)

There's nothing wrong at all with having a transient, real-time computed "currentTotalDuration" value and a "cachedTotalDuration" attribute. When "currentTotalDuration" is updated, throw it into "cachedTotalDuration" and it's done. It sounds perfectly reasonable to me to have a persistent cached attribute alongside a "live-computed" transient value that's only used when it needs to be updated.

I'm not familiar with Martin Brugger's Dependant Properties, but it sounds like most of the hard work is already done for you.

I hope I answered the question you actually asked. :-D

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文