Gajim - 2023-07-23


  1. kurion

    ``` def get_last_message_row(self) -> MessageRow | None: children = self._list_box.get_children() children.reverse() ```

  2. kurion

    what is the role of `reverse()`here?

  3. lovetox

    depends of the rest of the code

  4. lovetox

    reverse reverses a list

  5. kurion

    is there room for optimization for `get_last_message()` method in view.py?

  6. kurion

    I was wondering how costly it is to reverse the whole list to get the last item as the 0'th item.

  7. kurion

    I am aware that the number of rows in the `Listbox` of `ConversationView` is limited to 100.

  8. kurion

    But still...

  9. kurion

    Sorry the method I am talking about is `get_last_message_row`; missed the 'row' in the previous message.

  10. lovetox

    but we dont want always the last item in the list

  11. lovetox

    we only want it if its a message row

  12. kurion

    So `reverse` helps so that we have to check fewer rows?

  13. lovetox

    no, we want to iterate the list in revered order

  14. lovetox

    of course you can do this in many ways in python

  15. lovetox

    but its not simply accessing the last item, that would be trivial list[-1]

  16. lovetox

    you can ask the question what is the fastest way in python to traverse a list in reversed order

  17. kurion

    Yup, I get it now. There could be read markers, date rows as the last item in the list.

  18. lovetox

    i cant give you the answer, there might be faster ways then to reverse the list, but this can only found out by timing various methods

  19. lovetox

    as its not evident, what the C implementation of python actually does with the various approaches

  20. Link Mauve

    kurion, the first rule of performances optimisations is: profile.

  21. Link Mauve

    If your function doesn’t even appear on the profile, don’t bother optimising it.

  22. Link Mauve

    If you find out that your function is indeed slower than it could be, profile again at every step you take to optimise it.

  23. Link Mauve

    That way you will know which approaches improve things, which don’t do anything, and which actually decrease performances.

  24. Link Mauve

    It’s rarely intuitive, unless you have a very deep understanding of all of the layers, from the CPU architecture to the Python internals, so always profile.

  25. lovetox

    i think his first thought was, we want indeed only the last item of the list, in this case the assumption that reversing the list is inefficient would be correct

  26. Link Mauve

    Sure, but if this is a function called only once in a while optimising it doesn’t matter.

  27. kurion

    Link: Agreed. Premature optimization is a hazard.

  28. Link Mauve

    In this particular case though, assuming a large list and you only want to iterate on the last few items, the reversed() iterator would likely be a performance win.

  29. Link Mauve

    It iterates from the end of the list, but doesn’t actually reverse it.

  30. lovetox

    Yes

  31. lovetox

    and the motto about premature optimization, does not mean we should ignore obvious inefficent code

  32. lovetox

    just because it does not yet show up on some profile

  33. Link Mauve

    Of course.

  34. lovetox

    for me it just means we should not put in a disproportionate amount of time into optimizing something that may not even have a visible impact

  35. kurion

    I am really happy that trying to make modifications to a FOSS project is making me learning new thoughts and concepts from you guys.

  36. kurion

    I am really happy that trying to make modifications to a FOSS project is making me learn new thoughts and concepts from you guys.

  37. kurion

    Actually, I was trying to make Gajim as keyboard operable as possible for my blind friend (and for me too). So I made the shortcut Ctrl+L to move focus to the last selected/visited MessageRow from anywhere in the ChatPage. When no message is visited at all, focus goes to the last message. So that method will be used a considerable number of time in my use case.

  38. Link Mauve

    css-parser seems to be the slowest part of startup, with a tiny account.

  39. lovetox

    then use `for row in reversed(children):` its probably the fastest way

  40. Link Mauve

    kurion, I also happen to have a blind friend, this might help make her move away from Pidgin. :)

  41. kurion

    Since Link is active at the moment and he was interested in keyboard operability, I'd like to say that I have made some hotkeys for `MessageRow's and the `listbox` like copying multiple selected messages, quoting a message etc. The UX feels great already

  42. Link Mauve

    Did you start merging some of these features back to Gajim btw?

  43. kurion

    no, only made changes locally so far

  44. kurion

    some of the implementation contains code smell like using methods with underscore prefix outside of a class.

  45. kurion

    so I am afraid that some of the changes are not _pull-request-worthy_.

  46. nicoco

    hey lovetox! are PMs here disabled?

  47. lovetox

    yes, but dont seem to work

  48. nicoco

    oh OK. can you add me xmpp:nicoco@nicoco.fr maybe?

  49. kurion

    I'd like to have the 'Add Account' MenuItem listed in the Accounts ribbon menu at all times.

  50. kurion

    So I removed the conditional in the `build_accounts_menu` method in accounts.py

  51. lovetox

    hm this was the case anyway

  52. lovetox

    its just named differently

  53. lovetox

    Modify Accounts

  54. kurion

    yes just realized

  55. lovetox

    its always named Modify accounts, except there is no account configured at all

  56. lovetox

    and in this case the account wizard is shown

  57. lovetox

    so its very edge case that any normal user would ever see the "Add Account" Menu

  58. kurion

    I replaced `'app.accounts::` ``` add_account_item = Gio.MenuItem.new(_('_Add Account…'), 'app.accounts::') ``` with `'app.add-accounts::'

  59. kurion

    I replaced `'app.accounts::` in ``` add_account_item = Gio.MenuItem.new(_('_Add Account…'), 'app.accounts::') ``` with `'app.add-accounts::'

  60. kurion

    And it wasn't working.

  61. lovetox

    because that action odes not exist ..

  62. kurion

    then I changed ```('add-account', None),``` in const.py to ```('add-account', 's'),```

  63. kurion

    and it was okay.

  64. kurion

    sorry I put an extra 's' at the end of my previous message

  65. kurion

    But I wonder what made it work when I changed None to 's'.

  66. kurion

    I just followed the pattern of 'add-contact' and saw that it had an 's'.

  67. kurion

    What actually changed here?

  68. Link Mauve

    kurion, the 's' means that action takes a string as an argument.

  69. Link Mauve

    It’s like when you define a function, it can have no argument (e.g. foo()) or one string argument (e.g. bar("quux")).

  70. kurion

    Now I see why add-contact needs a string argument. It tells the function which account to add the contact to, right?

  71. lovetox

    and :: means empty string

  72. lovetox

    _on_add_contact_action

  73. lovetox

    then you will see what is done with the argument

  74. lovetox

    the argument is the jid of the contact

  75. lovetox

    and if its supplied we can skip the page where the user needs to input the jid, in the add-contact dialog

  76. kurion

    Oh, what a hit and a miss! :P

  77. kurion

    Why did it not work when add-account had None as the argument in const.py?

  78. kurion

    Still couldn't figure out why it didn't work when add-account had None as the argument in const.py?

  79. lovetox

    because the action passes a empty string

  80. lovetox

    :: means empty string

  81. kurion

    Oh, so if I remove the :: , it should go along well with None, right?

  82. lovetox

    yes, until it hits the callback

  83. lovetox

    which probably also exepects one argument

  84. kurion

    I see that in 'applications.py' `_on_add_account_action` does not need require an argument.

  85. kurion

    I see that in 'applications.py', `_on_add_account_action` does not need require an argument.

  86. kurion

    I see that in 'applications.py', `_on_add_account_action` does not require an argument.

  87. kurion

    It's None, acually

  88. kurion

    Thanks for the help. It is working now

  89. ham5urg

    Has https://dev.gajim.org/gajim/gajim-plugins/-/milestones/2#tab-issues entered a release? None is stated at the site.