Hey, quick question. I’m working on the `DatePick...
# compose
v
Hey, quick question. I’m working on the
DatePicker
and we use
java.util.Calendar
in a few date helper functions. These helpers can get called a lot while creating the calendar days, so I was looking at whether it makes sense to reuse the "Calendar" instead of creating a new one each time. Since
Calendar
is mutable, I don’t want to use one shared instance. I was thinking about
ThreadLocal<Calendar>
instead. Does anyone have a recommendation for this in Compose? Is
ThreadLocal
reasonable here, or would you keep creating a new
Calendar
unless we see an actual performance issue?
m
Is
ThreadLocal
reasonable here,
IMHO, no.
ThreadLocal
!= "coroutine local".
would you keep creating a new
Calendar
unless we see an actual performance issue?
Calendar
ought to be very cheap to instantiate. Don't create a million instances in a tight loop. Otherwise I would not worry about it unless you see a concrete performance issue.
v
Yeah, makes sense. I’ll leave it as it is for now and only look at changing it if we actually see a performance issue. Thanks for the point about
ThreadLocal
as well.
👍🏻 1