robrix icon indicating copy to clipboard operation
robrix copied to clipboard

Restructure `RoomsList` to store the list of `all_rooms` as a HashMap keyed by room ID

Open kevinaboos opened this issue 1 year ago • 8 comments

The full set/list of all rooms should not be ordered by default, which is what's currently happening implicitly because RoomsList::all_rooms is a Vec.

This is also especially relevant since we have some pending PRs about ordering/sorting/filtering the rooms list, so basically we're already encountering the need to separate the concern of storing the list from the concern of displaying the ordered/filtered list.

That would remove the need for the newly-added additional field RoomScreen::rooms_list_owned_room_id_map too.

Originally posted by @kevinaboos in https://github.com/project-robius/robrix/pull/181#discussion_r1796231692

kevinaboos avatar Oct 11 '24 00:10 kevinaboos

I am looking at this : )

aaravlu avatar Oct 12 '24 02:10 aaravlu

Our intention is to change Vec<RoomPreviewEntry> to HashMap<OwnedRoomID, RoomPreviewEntry>, right?

aaravlu avatar Oct 12 '24 02:10 aaravlu

Btw, I think if we want to use HashMap instead of normal tuple, we should avoid the standard library HashMap, its performance is very poor (not as good as Java), let me see what high-performance HashMap is available on crates.io : )

aaravlu avatar Oct 12 '24 02:10 aaravlu

I am a little pulzz about this, does the OwnedRoomID under RoomPerviewEntry need to be removed?

aaravlu avatar Oct 12 '24 05:10 aaravlu

This has already been self-assigned to me, but sure, you can take a look at it.

Our intention is to change Vec<RoomPreviewEntry> to HashMap<OwnedRoomID, RoomPreviewEntry>, right?

yep. I wouldn't be concerned about performance, even the largest matrix accounts have like ~2000 rooms. Also, don't get swept up in premature optimization. There are other hashmaps, e.g., hashbrown, but std is fine for now.

(its performance is very poor (not as good as Java)

I sincerely doubt that, but it's not important right now.

I am a little pulzz about this, does the OwnedRoomID under RoomPerviewEntry need to be removed?

nope, why? we'd still want easy access to a room's ID from its RoomPreviewEntry. Again, this issue is specifically about changing the choice of data structure to store the list of rooms, so let's restrict the scope to that.

kevinaboos avatar Oct 12 '24 05:10 kevinaboos

I see. Thanks very much: )

aaravlu avatar Oct 12 '24 10:10 aaravlu

Then, There is no Vec, and the index is not avilibale in HashMap. So, Should we change rooms_list_map from HashMap<u64, usize> to HashMap<OwnedRoomID, u64> ? (u64 is Widget ID) :)

aaravlu avatar Oct 13 '24 04:10 aaravlu

One last question, why my pr cannot checks automatically?, thanks :)

aaravlu avatar Oct 13 '24 04:10 aaravlu

what PR are you referring to? Also we don't have any checks, I removed the old one but will add some basic ones later.

kevinaboos avatar Oct 30 '24 23:10 kevinaboos