Issue Priority
Medium
Issue Description
getContactById (and msg.getContact()) calls Store.BusinessProfile.fetchBizProfile(wid) on every invocation. This function always makes a network round-trip to WhatsApp servers (~85-100ms per call), even when the result is already available in the local BusinessProfileCollection.
The BusinessProfileCollection already has find() and get() methods that check the local cache first and only fetch from the server when the entry is missing, exactly like Store.Contact.find() works for contacts.
Since getContact is often called multiple times per message (from event handlers, middleware, etc.), this adds hundreds of milliseconds of unnecessary latency per message. Under load (e.g. receiving many messages at once), the concurrent network calls can stack up significantly.
Steps To Reproduce
- Connect a client and receive a message
- Call
msg.getContact() - takes ~100ms due to fetchBizProfile
- Call
msg.getContact() again for the same contact - still ~100ms
- Meanwhile,
Store.BusinessProfile.get(wid) returns the same result in 0ms
Evidence
Tested directly in WhatsApp Web DevTools console:
// fetchBizProfile - always makes a network call
Store.BusinessProfile.fetchBizProfile(wid) -> ~95ms (every time)
// get() - reads from local collection cache
Store.BusinessProfile.get(wid) -> 0.005ms
// find() - cache first, fetches only if missing
Store.BusinessProfile.find(wid) -> 0.065ms (cached) / ~85ms (uncached)
All three methods return the exact same object reference (=== is true) when the entry exists in the cache.
For LID contacts, the first fetchBizProfile call can take 500-750ms, making the impact even larger.
Proposed Fix
In src/util/Injected/Utils.js, replace:
const bizProfile = await window.Store.BusinessProfile.fetchBizProfile(wid);
with:
const bizProfile = await window.Store.BusinessProfile.find(wid);
find() checks the local BusinessProfileCollection cache first and only fetches from the server when the entry is not present. This matches the pattern already used for Store.Contact.find(wid) on the line above.
WhatsApp Account Type
Standard
Authentication Strategy
LocalAuth
whatsapp-web.js Version
1.26.1-alpha.2
WhatsApp Web Version
2.3000+
Browser Type
Chromium
Browser Version
Chrome 145
Computer OS Version
Windows 11
Phone OS Version
Android 14
Node.js Version
20.x
Checklist
Issue Priority
Medium
Issue Description
getContactById(andmsg.getContact()) callsStore.BusinessProfile.fetchBizProfile(wid)on every invocation. This function always makes a network round-trip to WhatsApp servers (~85-100ms per call), even when the result is already available in the localBusinessProfileCollection.The
BusinessProfileCollectionalready hasfind()andget()methods that check the local cache first and only fetch from the server when the entry is missing, exactly likeStore.Contact.find()works for contacts.Since
getContactis often called multiple times per message (from event handlers, middleware, etc.), this adds hundreds of milliseconds of unnecessary latency per message. Under load (e.g. receiving many messages at once), the concurrent network calls can stack up significantly.Steps To Reproduce
msg.getContact()- takes ~100ms due tofetchBizProfilemsg.getContact()again for the same contact - still ~100msStore.BusinessProfile.get(wid)returns the same result in 0msEvidence
Tested directly in WhatsApp Web DevTools console:
All three methods return the exact same object reference (
===is true) when the entry exists in the cache.For LID contacts, the first
fetchBizProfilecall can take 500-750ms, making the impact even larger.Proposed Fix
In
src/util/Injected/Utils.js, replace:with:
find()checks the localBusinessProfileCollectioncache first and only fetches from the server when the entry is not present. This matches the pattern already used forStore.Contact.find(wid)on the line above.WhatsApp Account Type
Standard
Authentication Strategy
LocalAuth
whatsapp-web.js Version
1.26.1-alpha.2
WhatsApp Web Version
2.3000+
Browser Type
Chromium
Browser Version
Chrome 145
Computer OS Version
Windows 11
Phone OS Version
Android 14
Node.js Version
20.x
Checklist