Automattic / Automattic/jetpack
Jetpack slows site by 400ms when there is an Instagram url
- Dominant language
- PHP
- Stars
- 1.8k
- Forks
- 898
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 774
Description
We are seeing a slow down of 400ms when we enable Jetpack on posts that contains an Instagram url.
This seems to be caused by the Jetpack automatic embed for Instagram https://github.com/Automattic/jetpack/blob/e4477ebb9e13752a04776421351b7809039baf10/modules/shortcodes/instagram.php#L65
It does an http request to the `oembed` Instagram api and uses the WP Object Cache to cache the results. However by default the WP Object Cache is valid only for the executing request unless you add a persistent storage (apcu, memcached, redis etc).
The default WP Core oembed implementation uses the database **postmeta** to cache oembed results and this issue doesn't happen.
https://github.com/WordPress/WordPress/blob/5d1e06f93925e23ddec79e643d4ce4c963d46f14/wp-includes/class-wp-embed.php#L276
Is there a specific reason for which Jetpack replaces the default oembed core implementation?
Why the Jetpack implementation uses WP Object Cache and not **postmeta** like wp core for caching?
Contributor guide
Research direction
Compare Jetpack's modules/shortcodes/instagram.php at line 65 with WordPress's wp-includes/class-wp-embed.php at line 276, focusing on the Instagram oEmbed request and caching behavior described in the issue. Reproduce the slowdown on a post containing an Instagram URL, then establish whether the caching difference explains the reported 400ms delay and document the resulting decision or change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100