Skip to content

Refactored service binding#66

Open
spoenemann wants to merge 6 commits intomainfrom
service-refactor
Open

Refactored service binding#66
spoenemann wants to merge 6 commits intomainfrom
service-refactor

Conversation

@spoenemann
Copy link
Copy Markdown
Member

I feel the service container approach introduced in #6 is too complicated. I propose to simplify it as done in this PR.

We define a service.Container utility where you can register (MustPut or MustOverride) and retrieve (Get or MustGet) service instances. There's no "injection" – every service simply keeps a pointer to the service container and retrieves things when they're needed.

Performance Impact

I added a helper program to run a standardized benchmark:

go run ./internal/bench -runs 30 -cpu 1

On main:

MB/s:        min 3.380, avg 3.465, max 3.520
ms/resource: min 1.4710, avg 1.4953, max 1.5310

On this PR:

MB/s:        min 3.400, avg 3.456, max 3.510
ms/resource: min 1.4740, avg 1.4991, max 1.5230

This is 0.25% slower than before, probably due to the hash map lookups.

@spoenemann spoenemann requested a review from msujew April 30, 2026 10:08
Copy link
Copy Markdown
Member

@msujew msujew left a comment

Choose a reason for hiding this comment

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

Thanks, makes this a lot easier to understand.

Comment thread examples/statemachine/parser_gen.go
Comment thread util/service/service.go Outdated
Comment thread util/service/service.go Outdated
Comment thread workspace/document_manager.go
Comment thread util/service/service.go
Comment thread linking/linker.go
@spoenemann
Copy link
Copy Markdown
Member Author

spoenemann commented Apr 30, 2026

With the service caching, we're even 0.3% faster than on main:

MB/s:        min 3.430, avg 3.477, max 3.580
ms/resource: min 1.4460, avg 1.4902, max 1.5110

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