Skip to content
This repository has been archived by the owner on Jan 30, 2025. It is now read-only.

Refactor Sobek out of screenshots and byte pointer changes #1198

Merged
merged 5 commits into from
Jan 31, 2024

Conversation

ankur22
Copy link
Collaborator

@ankur22 ankur22 commented Jan 29, 2024

What?

This refactors the parsing of the goja options for frame.screenshot and page.screenshot to the mapping layer, as well as moving goja out of screenshotter. This means that the screenshot business logic is free of goja.

It also changes the screenshotter to return a []byte instead of a pointer to it (*[]byte).

Why?

The options should be parsed out of the goja.Value representation in the mapping layer to avoid goja escaping into the business logic which makes the business logic more complex and this will also help if we convert this method into async.

There's no reason to return a *[]byte as far as i can tell.

Checklist

  • I have performed a self-review of my code
  • I have added tests for my changes
  • I have commented on my code, particularly in hard-to-understand areas

Related PR(s)/Issue(s)

Updates: grafana/k6#4219

@ankur22 ankur22 changed the title Refactor screenshots goja parsing and byte pointer Refactor goja out of screenshots and byte pointer changes Jan 29, 2024
@ankur22 ankur22 requested a review from inancgumus January 29, 2024 17:40
Copy link
Member

@inancgumus inancgumus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! If it isn't too much work for you, could we detach the file persisting logic out of this PR and make this PR focus only on de-gojafying? I believe adding the file persisting logic should be straightforward after this. Also, we'll make the Screenshot accept an interface later. This way, we can avoid double work, and it'll also help us keep the commit history cleaner. Thanks.

@ankur22
Copy link
Collaborator Author

ankur22 commented Jan 30, 2024

Yep, this was done after the persister work. I believe this PR is separate from the Persister work, although it does depend on it unfortunately. I'd rather keep this as is and merge later once the persister PRs are merged into main.

@ankur22 ankur22 force-pushed the refactor/use-local-persister branch 6 times, most recently from f161c6a to 3cc7c51 Compare January 30, 2024 11:51
@ankur22 ankur22 force-pushed the refactor/screenshots-goja-bytes branch from f5d84de to ba94df5 Compare January 30, 2024 12:09
@ankur22 ankur22 changed the base branch from refactor/use-local-persister to main January 30, 2024 12:13
@ankur22 ankur22 changed the base branch from main to refactor/use-local-persister January 30, 2024 12:14
@ankur22 ankur22 marked this pull request as draft January 30, 2024 12:14
@ankur22 ankur22 force-pushed the refactor/use-local-persister branch 2 times, most recently from c2f30b9 to ab79ae7 Compare January 31, 2024 09:44
Base automatically changed from refactor/use-local-persister to main January 31, 2024 10:18
@ankur22 ankur22 force-pushed the refactor/screenshots-goja-bytes branch from ba94df5 to ebec386 Compare January 31, 2024 11:36
@ankur22 ankur22 marked this pull request as ready for review January 31, 2024 11:38
@ankur22 ankur22 requested a review from inancgumus January 31, 2024 11:38
Copy link
Member

@inancgumus inancgumus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nice 🎉 Some suggestions.

browser/mapping.go Outdated Show resolved Hide resolved
common/screenshotter.go Outdated Show resolved Hide resolved
common/screenshotter.go Outdated Show resolved Hide resolved
@ankur22 ankur22 force-pushed the refactor/screenshots-goja-bytes branch from ebec386 to 0a093fd Compare January 31, 2024 13:58
browser/mapping.go Outdated Show resolved Hide resolved
browser/mapping.go Outdated Show resolved Hide resolved
browser/mapping.go Outdated Show resolved Hide resolved
common/screenshotter.go Outdated Show resolved Hide resolved
inancgumus
inancgumus previously approved these changes Jan 31, 2024
As far as I can tell there is no reason to return a pointer to the
slice of bytes, since the slice it self is referenced with a pointer.
The remote parser no longer works with goja so the result from evaluate
will not return a goja value. Now just type assert without goja.
@ankur22 ankur22 force-pushed the refactor/screenshots-goja-bytes branch from f8799f2 to 0cddf7c Compare January 31, 2024 15:22
To fix the linter issue
@ankur22 ankur22 requested a review from inancgumus January 31, 2024 15:26
@ankur22 ankur22 merged commit 3349d0b into main Jan 31, 2024
17 checks passed
@ankur22 ankur22 deleted the refactor/screenshots-goja-bytes branch January 31, 2024 15:50
@inancgumus inancgumus changed the title Refactor goja out of screenshots and byte pointer changes Refactor Sobek out of screenshots and byte pointer changes Jun 21, 2024
@inancgumus inancgumus added refactor stability runtime stability improvements labels Nov 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
refactor stability runtime stability improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants