Project

General

Profile

Actions

Patch #44423

closed

Improve performance when formatting user mentions

Added by Marius BĂLTEANU 2 days ago. Updated about 14 hours ago.

Status:
Closed
Priority:
Normal
Category:
Performance
Target version:

Description

When formatting text containing user mentions (@login), Redmine performs individual database queries for each mention encountered, especially after #39528:
  • User.visible.find_by_login in parse_redmine_links
  • object.visible?(user) (and related membership/role checks) in link_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:
  1. Memoize User.visible.find_by_login lookups in parse_redmine_links so identical user logins are queried from the database only once.
  2. Memoize object.visible?(user) per [object, user.id] in link_to_mention to 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

Related to Redmine - Feature #39528: Change mention link color for users without access to view issuesClosedMarius BĂLTEANUActions
Actions

Also available in: Atom PDF