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

Lesson 205: probably rust compiler could have deceived us #294

Open
hessenar opened this issue Sep 29, 2024 · 0 comments
Open

Lesson 205: probably rust compiler could have deceived us #294

hessenar opened this issue Sep 29, 2024 · 0 comments
Labels

Comments

@hessenar
Copy link
Contributor

Looking again at the functions initializing the devices, I can assume that the Rusty compiler could optimize this response and generate it at the compilation stage.
If it were interesting to check the formation of the response on the fly, then, probably, it is necessary to store these values ​​not in the code, but to take them from the database, external cache (Redis) or just from a file, for example. (if my proposal looks rough, then I apologize for my English)
If we want to check a static response, then in the code we can try to use sync.Pool(but I'm not an expert in go, it would be good if someone else watched it)

var pool = sync.Pool{
	New: func() interface{} {
		return &[...]Device{
			{UUID: "b0e42fe7-31a5-4894-a441-007e5256afea", Mac: "5F-33-CC-1F-43-82", Firmware: "2.1.6"},
			{UUID: "0c3242f5-ae1f-4e0c-a31b-5ec93825b3e7", Mac: "EF-2B-C4-F5-D6-34", Firmware: "2.1.5"},
			{UUID: "b16d0b53-14f1-4c11-8e29-b9fcef167c26", Mac: "62-46-13-B7-B3-A1", Firmware: "3.0.0"},
			{UUID: "51bb1937-e005-4327-a3bd-9f32dcf00db8", Mac: "96-A8-DE-5B-77-14", Firmware: "1.0.1"},
			{UUID: "e0a1d085-dce5-48db-a794-35640113fa67", Mac: "7E-3B-62-A6-09-12", Firmware: "3.5.6"},
		}
	},
}
func (ms *MyServer) getDevices(w http.ResponseWriter, req *http.Request) {
	devices := pool.Get()
	defer pool.Put(dev)
	renderJSON(w, &devices)
}
@antonputra antonputra added the rust label Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants