osu icon indicating copy to clipboard operation
osu copied to clipboard

Cache created judgement in `HitObject`

Open EVAST9919 opened this issue 1 year ago • 2 comments

These values have been taken during beatmap loading (going from song-select to player loader and waiting until player screen push)

master pr
master-loading pr-loading

EVAST9919 avatar Feb 10 '24 11:02 EVAST9919

See https://github.com/ppy/osu/issues/27104#issuecomment-1936997683

EVAST9919 avatar Feb 10 '24 12:02 EVAST9919

Reopening since it improves allocations during beatmap loading (OP has been updated), and potentially has benefits elsewhere.

EVAST9919 avatar Feb 10 '24 17:02 EVAST9919

I think this is fine for as long as Judgement is only used to ferry fixed data. Looking through a few rulesets, it doesn't look like implementations do anything other than override MaxResult, which is good because that isn't really supported anyway.

We'll change this class in the future, at which time I'd reconsider the semantics around it - likely making it not a class and potentially moving it to the ctor.

Curious what @bdach thinks of this PR.

smoogipoo avatar Feb 14 '24 05:02 smoogipoo

I was deferring review of this as it seemed relatively low priority. Without looking the diff over, mixed thoughts because I'm scared of this going wrong and storing data it shouldn't be storing, but also thinking that if we're ever to actually fix issues in editor stemming from lack of frame stability without relying on frame stability it'd be by storing stuff more permanently to hitobjects rather than rely on DHOs for storing object state, which this helps in.

bdach avatar Feb 14 '24 08:02 bdach

One other thing to consider - and bear in mind I'm just listing my thoughts and doesn't necessarily affect this PR - is that at some point we'll probably want to pool HitObjects as they're the single highest source of GC pressure affecting in particular diffcalc. Anything stateful inside HitObject should probably consider that it may become transient at some point so that we don't inadvertently lock ourselves into more breaking changes further down the track

smoogipoo avatar Feb 14 '24 08:02 smoogipoo

the judgement class really needs very strong xmldoc saying that it shouldn't be storing state. or it should be forcefully sealed from adding new fields if that's even a thing we can do.

peppy avatar Feb 14 '24 19:02 peppy

or it should be forcefully sealed from adding new fields

Unfortunately not 😢

But yeah I would see it going in a struct direction, effectively sealing it. Something like:

ctor()
{
    Criteria = new JudgementCriteria
    {
        MaxResult = LargeTickHit,
        [MinResult = ...]
    }
}

smoogipoo avatar Feb 15 '24 08:02 smoogipoo

Sounds good.

peppy avatar Feb 15 '24 09:02 peppy