Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
eb871213
Unverified
Commit
eb871213
authored
4 years ago
by
Martin Holst Swende
Committed by
GitHub
4 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core/bloombits: faster generator (#21625)
* core/bloombits: add benchmark * core/bloombits: optimize inserts
parent
2b2fd741
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
9 deletions
+53
-9
generator.go
core/bloombits/generator.go
+14
-9
generator_test.go
core/bloombits/generator_test.go
+39
-0
No files found.
core/bloombits/generator.go
View file @
eb871213
...
...
@@ -65,18 +65,23 @@ func (b *Generator) AddBloom(index uint, bloom types.Bloom) error {
}
// Rotate the bloom and insert into our collection
byteIndex
:=
b
.
nextSec
/
8
bitMask
:=
byte
(
1
)
<<
byte
(
7
-
b
.
nextSec
%
8
)
for
i
:=
0
;
i
<
types
.
BloomBitLength
;
i
++
{
bloomByteIndex
:=
types
.
BloomByteLength
-
1
-
i
/
8
bloomBitMask
:=
byte
(
1
)
<<
byte
(
i
%
8
)
if
(
bloom
[
bloomByteIndex
]
&
bloomBitMask
)
!=
0
{
b
.
blooms
[
i
][
byteIndex
]
|=
bitMask
bitIndex
:=
byte
(
7
-
b
.
nextSec
%
8
)
for
byt
:=
0
;
byt
<
types
.
BloomByteLength
;
byt
++
{
bloomByte
:=
bloom
[
types
.
BloomByteLength
-
1
-
byt
]
if
bloomByte
==
0
{
continue
}
base
:=
8
*
byt
b
.
blooms
[
base
+
7
][
byteIndex
]
|=
((
bloomByte
>>
7
)
&
1
)
<<
bitIndex
b
.
blooms
[
base
+
6
][
byteIndex
]
|=
((
bloomByte
>>
6
)
&
1
)
<<
bitIndex
b
.
blooms
[
base
+
5
][
byteIndex
]
|=
((
bloomByte
>>
5
)
&
1
)
<<
bitIndex
b
.
blooms
[
base
+
4
][
byteIndex
]
|=
((
bloomByte
>>
4
)
&
1
)
<<
bitIndex
b
.
blooms
[
base
+
3
][
byteIndex
]
|=
((
bloomByte
>>
3
)
&
1
)
<<
bitIndex
b
.
blooms
[
base
+
2
][
byteIndex
]
|=
((
bloomByte
>>
2
)
&
1
)
<<
bitIndex
b
.
blooms
[
base
+
1
][
byteIndex
]
|=
((
bloomByte
>>
1
)
&
1
)
<<
bitIndex
b
.
blooms
[
base
][
byteIndex
]
|=
(
bloomByte
&
1
)
<<
bitIndex
}
b
.
nextSec
++
return
nil
}
...
...
This diff is collapsed.
Click to expand it.
core/bloombits/generator_test.go
View file @
eb871213
...
...
@@ -58,3 +58,42 @@ func TestGenerator(t *testing.T) {
}
}
}
func
BenchmarkGenerator
(
b
*
testing
.
B
)
{
var
input
[
types
.
BloomBitLength
][
types
.
BloomByteLength
]
byte
b
.
Run
(
"empty"
,
func
(
b
*
testing
.
B
)
{
b
.
ReportAllocs
()
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
// Crunch the input through the generator and verify the result
gen
,
err
:=
NewGenerator
(
types
.
BloomBitLength
)
if
err
!=
nil
{
b
.
Fatalf
(
"failed to create bloombit generator: %v"
,
err
)
}
for
j
,
bloom
:=
range
input
{
if
err
:=
gen
.
AddBloom
(
uint
(
j
),
bloom
);
err
!=
nil
{
b
.
Fatalf
(
"bloom %d: failed to add: %v"
,
i
,
err
)
}
}
}
})
for
i
:=
0
;
i
<
types
.
BloomBitLength
;
i
++
{
rand
.
Read
(
input
[
i
][
:
])
}
b
.
Run
(
"random"
,
func
(
b
*
testing
.
B
)
{
b
.
ReportAllocs
()
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
// Crunch the input through the generator and verify the result
gen
,
err
:=
NewGenerator
(
types
.
BloomBitLength
)
if
err
!=
nil
{
b
.
Fatalf
(
"failed to create bloombit generator: %v"
,
err
)
}
for
j
,
bloom
:=
range
input
{
if
err
:=
gen
.
AddBloom
(
uint
(
j
),
bloom
);
err
!=
nil
{
b
.
Fatalf
(
"bloom %d: failed to add: %v"
,
i
,
err
)
}
}
}
})
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment