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

Performance Question about service instnace : getInstance(i Injector) (T, error) #66

Open
kcmvp opened this issue Mar 26, 2024 · 1 comment
Milestone

Comments

@kcmvp
Copy link

kcmvp commented Mar 26, 2024

func (s *serviceEager[T]) getInstance(i Injector) (T, error) {
	frame, ok := stacktrace.NewFrameFromCaller()
	if ok {
		s.mu.Lock()
		s.invokationFrames = append(s.invokationFrames, frame) // @TODO: potential memory leak
		s.mu.Unlock()
	}

	return s.instance, nil
}

above code is from https://github.com/samber/do/blob/v2-%F0%9F%9A%80/service_eager.go,

right now I am using do by generate a global singleton scope and get the service on demand. but there is a call to get call
stack everytime I try to get the instnace
frame, ok := stacktrace.NewFrameFromCaller(), in fact this methos is not exported just for internal usagae. It will decrease the system performance. is there way to optimize the design?

@samber
Copy link
Owner

samber commented May 5, 2024

3 ideas come to my mind:

  • add a parameter in the root scope
  • add a parameter globally in the lib (eg: do.TraceInvocation = true)
  • enable only if a debugging library is loaded (like github.com/samber/do/http/gin/v2)

I'm adding this to v2.1 roadmap.

@samber samber added this to the v2.1 milestone May 5, 2024
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

No branches or pull requests

2 participants