Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buffer: Add proper lock mechanism to lock the full LineArray instead of single lines #3224

Merged
merged 6 commits into from
Apr 5, 2024

Conversation

JoeKar
Copy link
Collaborator

@JoeKar JoeKar commented Apr 2, 2024

The PRs #3062 and #3208 in combination revealed a long existing race problem which manifested itself (after the merge of the PRs) sporadically in the MacOS tests, which failed.
The reason for the fail usually is the access of the async highlighter code (triggered by UpdateRules()) to lines which don't exist any longer, since they're already removed by the testing code.

With the fine tuning of #3220 we should be able to catch such situations earlier...at least when they are caused by builtin functionalities.

@JoeKar JoeKar requested a review from dmaluka April 2, 2024 19:18
internal/buffer/line_array.go Show resolved Hide resolved
internal/buffer/line_array.go Outdated Show resolved Hide resolved
internal/buffer/line_array.go Outdated Show resolved Hide resolved
pkg/highlight/highlighter.go Outdated Show resolved Hide resolved
pkg/highlight/highlighter.go Show resolved Hide resolved
internal/buffer/line_array.go Show resolved Hide resolved
@JoeKar JoeKar force-pushed the fix/line-synchronization branch 2 times, most recently from ffe83d8 to b47fa04 Compare April 4, 2024 21:22
internal/buffer/line_array.go Outdated Show resolved Hide resolved
pkg/highlight/highlighter.go Outdated Show resolved Hide resolved
pkg/highlight/highlighter.go Show resolved Hide resolved
internal/buffer/line_array.go Show resolved Hide resolved
internal/buffer/line_array.go Show resolved Hide resolved
pkg/highlight/highlighter.go Show resolved Hide resolved
@JoeKar JoeKar force-pushed the fix/line-synchronization branch 3 times, most recently from dc6da7b to c359c8d Compare April 5, 2024 09:31
@JoeKar
Copy link
Collaborator Author

JoeKar commented Apr 5, 2024

The execution time of the test increases (for me) from ~10ms to ~100ms, so it's round about ten times slower now.

internal/buffer/buffer.go Outdated Show resolved Hide resolved
@dmaluka
Copy link
Collaborator

dmaluka commented Apr 5, 2024

The execution time of the test increases (for me) from ~10ms to ~100ms, so it's round about ten times slower now.

I see the same, but I believe it increases just because of uncommenting InitRuntimeFiles(false), i.e. ~10ms is when the test is actually not doing any highlighting.

BTW you can run some actual benchmarks, by running go test -bench=. inside internal/buffer/. I've already run them (a couple of days ago, i.e. not with your newest version of the race fix) and didn't see any actual difference with and w/o the race fix.

JoeKar and others added 6 commits April 5, 2024 14:19
This is necessary as a preparation to introduce a lock for the whole LineArray.
The modification can then be done without trying to lock the same lock twice.

Co-authored-by: Dmytro Maluka <dmitrymaluka@gmail.com>
...which isn't used so far and probably handled better in a different way.
This is achieved by the usage of the new `LineArray` locking machanism,
which prevents the interruption in the moment of modifications like insertion
or removal of lines.

Co-authored-by: Dmytro Maluka <dmitrymaluka@gmail.com>
...since we fixed the race between the syntax highlighting and the buffer
editing.
@JoeKar JoeKar force-pushed the fix/line-synchronization branch from c359c8d to a3ca054 Compare April 5, 2024 12:25
@JoeKar
Copy link
Collaborator Author

JoeKar commented Apr 5, 2024

BTW you can run some actual benchmarks, by running go test -bench=. inside internal/buffer/.

Ah, yes...the initial highlighting is affecting the execution the most and has the most impact at BenchmarkCreateAndClose*, while the other tests/benchmarks remain more or less the same.

@JoeKar JoeKar merged commit 467c71d into zyedidia:master Apr 5, 2024
3 checks passed
@JoeKar JoeKar deleted the fix/line-synchronization branch April 5, 2024 22:09
@dmaluka
Copy link
Collaborator

dmaluka commented Apr 6, 2024

Just for others' information: #3220 contains the discussion & investigation which has led to this PR.

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.

2 participants