linuxboot / linuxboot/fiano

Discussion: extra copying justification

Open
#304 15 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
373
Forks
59
PR merge metrics
No merged PRs in 30d

Description

Hello.

I'm wondering if there's any specific reason of this copyings:
```
newBuf := data[:fv.Length]
fv.buf = make([]byte, fv.Length)
copy(fv.buf, newBuf)
```

I've removed copying in my sandbox and everything still works. Also:
```
BenchmarkFianoUEFIParse-8 26365509 ns/op 730 B/op 10 allocs/op
```
vs
```
BenchmarkFianoUEFIParse-8 33305961 ns/op 33555673 B/op 13 allocs/op
```

So this copyings creates a lot of extra memory consumption for nothing.

~~Also in my case this copyings creates some obstacles, because I'm trying to calculate offsets by subtracting one pointer from another.~~ (this point is not relevant anymore)

```
[xaionaro@void fiano]$ go test ./...
ok github.com/linuxboot/fiano/cmds/fmap 0.097s
ok github.com/linuxboot/fiano/cmds/fspinfo 0.024s
? github.com/linuxboot/fiano/cmds/glzma [no test files]
? github.com/linuxboot/fiano/cmds/guid2english [no test files]
? github.com/linuxboot/fiano/cmds/utk [no test files]
ok github.com/linuxboot/fiano/integration 4.587s
ok github.com/linuxboot/fiano/pkg/compression 6.119s
ok github.com/linuxboot/fiano/pkg/fmap 0.030s
ok github.com/linuxboot/fiano/pkg/fsp 0.012s
ok github.com/linuxboot/fiano/pkg/guid 0.041s
ok github.com/linuxboot/fiano/pkg/guid2english 0.020s
? github.com/linuxboot/fiano/pkg/knownguids [no test files]
ok github.com/linuxboot/fiano/pkg/uefi 0.004s
? github.com/linuxboot/fiano/pkg/unicode [no test files]
? github.com/linuxboot/fiano/pkg/utk [no test files]
ok github.com/linuxboot/fiano/pkg/visitors 6.907s
? github.com/linuxboot/fiano/scripts/checklicenses [no test files]
? github.com/linuxboot/fiano/scripts/namecollect [no test files]
[xaionaro@void fiano]$ go test ./... -race
ok github.com/linuxboot/fiano/cmds/fmap 4.040s
ok github.com/linuxboot/fiano/cmds/fspinfo 1.010s
? github.com/linuxboot/fiano/cmds/glzma [no test files]
? github.com/linuxboot/fiano/cmds/guid2english [no test files]
? github.com/linuxboot/fiano/cmds/utk [no test files]
ok github.com/linuxboot/fiano/integration 20.109s
ok github.com/linuxboot/fiano/pkg/compression 51.295s
ok github.com/linuxboot/fiano/pkg/fmap 1.082s
ok github.com/linuxboot/fiano/pkg/fsp 1.009s
ok github.com/linuxboot/fiano/pkg/guid 1.026s
ok github.com/linuxboot/fiano/pkg/guid2english 1.422s
? github.com/linuxboot/fiano/pkg/knownguids [no test files]
ok github.com/linuxboot/fiano/pkg/uefi 1.030s
? github.com/linuxboot/fiano/pkg/unicode [no test files]
? github.com/linuxboot/fiano/pkg/utk [no test files]
ok github.com/linuxboot/fiano/pkg/visitors 106.731s
? github.com/linuxboot/fiano/scripts/checklicenses [no test files]
? github.com/linuxboot/fiano/scripts/namecollect [no test files]
```

So the question is would you accept a PR where I just remove this copyings?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the buffer-copy sequence shown in the issue and review how the buffer is used after parsing. Run the reported benchmarks, then go test ./... and go test ./... -race; done means confirming the copy can be removed without changing ownership, lifetime, parsing behavior, or test results.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
embedded-iot, performance
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.