RocketChat / RocketChat/Rocket.Chat
Performance: Optimize sequential OEmbed fetching in rocketUrlParser to run concurrently
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 46.1k
- Forks
- 13.9k
- Avg merge
- 3d 3h
- Merged PRs (30d)
- 130
Description
Currently, the rocketUrlParser in the AfterSaveOEmbed hook processes message URLs sequentially using a for await...of loop. When a user sends a single message containing multiple external URLs, the server halts and waits for each parseUrl() HTTP request to completely resolve before initiating the next one.This creates an $O(N)$ network latency bottleneck. If a message contains 4 URLs, and each takes 1.5 seconds to respond, the thread is blocked for 6 seconds. Refactoring this to fetch the metadata concurrently (e.g., using Promise.all or Promise.allSettled) will reduce the total processing time to the duration of the single slowest request.
Steps to reproduce:
- Boot up a local Rocket.Chat development server.
- Ensure OEmbed/Link Previews are enabled in Administration -> Settings -> Message.
- Send a single message in any channel containing 4 or 5 different external URLs (e.g., various news articles or YouTube links).
- Trace the server execution logs or observe the response time. The URLs are fetched one after the other, causing a noticeable delay in processing the final message state.
Expected behavior:
The server should initiate the OEmbed HTTP requests for all valid URLs in the message array concurrently, drastically reducing the total time spent in the rocketUrlParser hook.
Actual behavior:
The server waits for parseUrl(item.url) to completely finish before starting the network request for the next URL in the array, creating a sequential blocking queue.
Server Setup Information:
- Version of Rocket.Chat Server: develop branch (Latest)
- License Type: Community
- Number of Users: Local Dev (1)
- Operating System: Linux/WSL
- Deployment Method: Local Development
- Number of Running Instances: 1
- DB Replicaset Oplog: Enabled
- NodeJS Version: 22.16.0
- MongoDB Version: 8.2.4
Client Setup Information
Desktop App or Browser Version: Chrome/Brave (Latest)
Operating System: Windows / Linux
Additional context
Target File: apps/meteor/app/lib/server/functions/hooks/AfterSaveOEmbed.ts
Target Function: rocketUrlParserI
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in apps/meteor/app/lib/server/functions/hooks/AfterSaveOEmbed.ts at the rocketUrlParser function, especially the for await...of loop and its parseUrl(item.url) calls. Confirm that valid URLs are initiated concurrently while preserving the hook’s existing behavior, then verify that processing time is no longer the sum of each request’s latency.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- backend, performance
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100