Actions
Patch #44423
closedImprove performance when formatting user mentions
Description
When formatting text containing user mentions (
@login), Redmine performs individual database queries for each mention encountered, especially after #39528:
User.visible.find_by_logininparse_redmine_linksobject.visible?(user)(and related membership/role checks) inlink_to_mention
On pages or long issue threads with multiple notes where active participants (assignee, author, reviewers) are mentioned repeatedly, this generates redundant database queries and adds avoidable rendering overhead.
Add in-memory memoization during the helper/formatting request lifecycle:- Memoize
User.visible.find_by_loginlookups inparse_redmine_linksso identical user logins are queried from the database only once. - Memoize
object.visible?(user)per[object, user.id]inlink_to_mentionto avoid redundant permission queries.
Benchmarks:
| Scenario | Before r24437 | After r24437 | with these patches | |
|---|---|---|---|---|
| 1. | Repeated mentions (5 users mentioned 20x = 100 mentions, 10 runs) | 213.59ms (2.136ms / mention) | 567.07ms (5.671ms / mention) | 3.38ms (0.034ms / mention) |
| 2. | 100 unique mentions (10 runs) | 218.35ms (2.184ms / mention) | 512.79ms (5.128ms / mention) | 4.18ms (0.042ms / mention) |
| 3. | 10 unique mentions (50 runs) | 21.91ms (2.191ms / mention) | 60.27ms (6.027ms / mention) | 0.67ms (0.067ms / mention) |
| 4. | 1 single mention (100 runs) | 2.57ms | 6.62ms | 0.36ms |
| 5. | 100 non-existent users (10 runs) | 99.46ms 110.76ms | 11.64ms |
Both patches attached.
Files
Related issues
Actions