Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Order tab complete by most recently spoke #341

Merged
merged 8 commits into from
Jul 19, 2016

Conversation

dbkr
Copy link
Member

@dbkr dbkr commented Jul 14, 2016

@kegsay
Copy link
Member

kegsay commented Jul 14, 2016

I thought we had last_active_ago for this so we didn't need to loop all the events in the room?

@dbkr
Copy link
Member Author

dbkr commented Jul 14, 2016

I think this is when they performed an action in any room though, as opposed to just the one we're in.

// build up a dict of when, in the history we have cached,
// each member last spoke
const lastSpoke = {};
const timelineEvents = room.getLiveTimeline().getEvents();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now depend on the events in the room to determine ordering, but we don't call _updateTabCompleteList when we get incoming events. We probably should.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point

@kegsay
Copy link
Member

kegsay commented Jul 14, 2016

I think this is when they performed an action in any room though, as opposed to just the one we're in.

Oh that rings a bell, carry on then.

dbkr added 2 commits July 14, 2016 11:40
.sende ris sometimes null: use getSender() which isn't and returns the userId which is what we actually want
Turns out this timeline is the other way around, so loop through the other way
@dbkr
Copy link
Member Author

dbkr commented Jul 14, 2016

ptal


// update ther tab complete list as it depends on who most recently spoke,
// and that has probably just changed
this._updateTabCompleteList();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be moved up so it is inside:

if (ev.getSender() !== MatrixClientPeg.get().credentials.userId) {
  // ...
}

I don't think there is any point in updating the tab-completion ordering with your own user.

@kegsay
Copy link
Member

kegsay commented Jul 14, 2016

LGTM aside from performance concern.

dbkr added 2 commits July 15, 2016 16:10
Now do a lot less when people speak. Also move more of the tab completion logic into TabComplete.js and out of RoomView.
@@ -45,21 +48,32 @@ class TabComplete {
this.isFirstWord = false; // true if you tab-complete on the first word
this.enterTabCompleteTimerId = null;
this.inPassiveMode = false;
this.memberTabOrder = {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this? A map? What are the keys? Integers to represent the ordering? User IDs? What are the values? Comment please!

}
this.memberTabOrder[member.userId] = this.memberOrderSeq++;
this._sortEntries();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really have to go through and re-sort the entire member list when someone speaks? I thought the whole point of this was to avoid doing that, and yet here we are. onMemberSpoke is called when RoomView.onRoomTimeline is called, and we don't save ourselves a sort operation (we know that member should be at the head of the list; they just spoke!). Likewise, _sortEntries doesn't appear to do any optimisations beyond saving ourselves the O(N) scan of the timeline which was done in _initSorting.

member: 2,
};

this.list.sort((a, b) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know what sorting algorithm this uses? The first sort will contain completely unsorted data, but subsequent sorts are done with nearly-sorted data (only 1 element needs shifting; the person who spoke). I care because this function is called for every incoming timeline event. If we use insertion sort this can be made very quick since we're operating on nearly-sorted data sets.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe it's specified, although you're correct: I'm assuming that sorting a very-nearly sorted list should be fast: at worst, I think it's about the same which, for the number of things we're sorting, is probably fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just did a bit of digging, and indeed it is not specified in ECMAScript. Each browser implements different sorting algorithms for Array#sort():

  • MergeSort for Mozilla
  • a mix of QuickSort/MergeSort/SelectionSort(!!!) for Chrome, depending on the types of elements inside the array.

Fun times.

@kegsay
Copy link
Member

kegsay commented Jul 19, 2016

LGTM

@dbkr dbkr merged commit 514bc2c into develop Jul 19, 2016
@richvdh richvdh deleted the dbkr/tab_complete_most_recently_spoke branch February 15, 2017 13:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants