Commit 8a6bca3
authored
Fix to remove needless allocations (performance) (plokhotnyuk#1335)
Before this fix, every decode operation would reallocate the `buf`
Array. This is because at the start of read, pos=head=0.
Then, because we've grown the buffer, at the end of the read operation
we'd allocate the array AGAIN to shrink it back because it is now larger
than the preferred buffer size config!
The problem started with the commit:
f0ebbe1 Code clean up (Andriy Plokhotnyuk) 2020-01-02|
```diff
- newPos
- } else {
- if (tail > 0) buf = java.util.Arrays.copyOf(buf, buf.length << 1)
- pos
- }
+ } else buf = java.util.Arrays.copyOf(buf, buf.length << 1)
```
This change restores the original check for the `tail > 0` which is used
to indicate that the buffer is currently empty (start of the read
operation) and we should not grow it.1 parent 10e8213 commit 8a6bca3
File tree
2 files changed
+8
-4
lines changed- jsoniter-scala-core
- js/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/core
- jvm-native/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/core
2 files changed
+8
-4
lines changedLines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4051 | 4051 | | |
4052 | 4052 | | |
4053 | 4053 | | |
4054 | | - | |
| 4054 | + | |
| 4055 | + | |
| 4056 | + | |
4055 | 4057 | | |
4056 | 4058 | | |
4057 | 4059 | | |
| |||
4490 | 4492 | | |
4491 | 4493 | | |
4492 | 4494 | | |
4493 | | - | |
| 4495 | + | |
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4506 | 4506 | | |
4507 | 4507 | | |
4508 | 4508 | | |
4509 | | - | |
| 4509 | + | |
| 4510 | + | |
| 4511 | + | |
4510 | 4512 | | |
4511 | 4513 | | |
4512 | 4514 | | |
| |||
4943 | 4945 | | |
4944 | 4946 | | |
4945 | 4947 | | |
4946 | | - | |
| 4948 | + | |
0 commit comments