Skip to content

[13.x] Decode job payload once - #61526

Merged
taylorotwell merged 1 commit into
laravel:13.xfrom
jackbayliss:13.x-memoize-json_decode
Sep 14, 2026
Merged

taylorotwell merged 1 commit into
laravel:13.xfrom
jackbayliss:13.x-memoize-json_decode

Conversation

@jackbayliss

@jackbayliss jackbayliss commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

I was poking and realised payload() is called for figuring out all the job settings like maxTries,retryUntil etc. In the Worker loop, but, it's decoded fresh each time.

RedisJob already decodes once into a decoded property, see #13952 but, of course not all the methods are called that way.

I think this should just be the default.
This helps if you have larger payloads mainly, so for smaller jobs there's no real difference.

SQS supports up to 1 MiB, Database and Redis can take more, so after some basic testing with about 200kb - 900kb its about 20% - 30% faster to finish a job just with this one change, Which of course is more meaningful the more jobs you process.

This PR just once's it

Sent to 13.x as I don't see how a payload would be expected to give a a different string on the second call, but happy to send to 14.x if you prefer? or refactor?

We could clean up the Redis job in 14.x, but open to whats easier for you 🖖🏻

@github-actions

Copy link
Copy Markdown

Thanks for submitting a PR!

Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@jackbayliss
jackbayliss marked this pull request as ready for review September 10, 2026 22:12
@taylorotwell

Copy link
Copy Markdown
Member

Think this could change the way jobs serialize in a way we don't want?

@jackbayliss

jackbayliss commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor Author

@taylorotwell I don't think so, it's serialized as normal via createPayload , it doesn't call this method

This method is called in the worker loop, so this PR stops the worker constantly calling json_decode on the raw payload which doesnt change. RedisJob does this, but doesn't utilise it fully

Double checked locally and the payload is the same

Happy to send it to master if there's a concern but lmk if im missing something stupid

Ty big dog

@timacdonald

Copy link
Copy Markdown
Member

Using the once helper would avoid the concern entirely, as the payload would be cached elsewhere in Magic Land ✨

@jackbayliss
jackbayliss marked this pull request as draft September 14, 2026 07:03
Update Job.php

test
@jackbayliss
jackbayliss force-pushed the 13.x-memoize-json_decode branch from aad0ec8 to 6523a10 Compare September 14, 2026 08:19
@jackbayliss

jackbayliss commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @timacdonald!

Adjusted to now use once

ty all 🫡

@jackbayliss
jackbayliss marked this pull request as ready for review September 14, 2026 08:27
@taylorotwell
taylorotwell merged commit e2733d0 into laravel:13.x Sep 14, 2026
54 checks passed
@jackbayliss
jackbayliss deleted the 13.x-memoize-json_decode branch September 14, 2026 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants