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

chore(lib/runtime/wasmer): import functions in a for loop #2650

Merged
merged 4 commits into from
Jul 11, 2022

Conversation

qdm12
Copy link
Contributor

@qdm12 qdm12 commented Jul 7, 2022

Changes

  • ImportsNodeRuntime: append functions in a for loop
  • ImportsNodeRuntime: remove no longer needed //nolint:gocyclo
  • ImportsNodeRuntime: update now deprecated .Append to be .AppendFunction
  • ImportsNodeRuntime: sort import appending alphabetically

Tests

Issues

Done whilst adding functions

Primary Reviewer

@kishansagathiya

@codecov
Copy link

codecov bot commented Jul 7, 2022

Codecov Report

Merging #2650 (14a0f83) into development (d2da7fb) will increase coverage by 0.58%.
The diff coverage is 96.87%.

@@               Coverage Diff               @@
##           development    #2650      +/-   ##
===============================================
+ Coverage        62.34%   62.93%   +0.58%     
===============================================
  Files              211      211              
  Lines            27343    27106     -237     
===============================================
+ Hits             17048    17059      +11     
+ Misses            8654     8486     -168     
+ Partials          1641     1561      -80     
Flag Coverage Δ
unit-tests 62.93% <96.87%> (+0.58%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
lib/runtime/wasmer/imports.go 55.03% <96.87%> (+6.88%) ⬆️
dot/network/inbound.go 92.98% <0.00%> (-7.02%) ⬇️
dot/network/block_announce.go 58.40% <0.00%> (-4.81%) ⬇️
dot/network/service.go 56.74% <0.00%> (-0.27%) ⬇️
dot/network/sync.go 5.26% <0.00%> (ø)
dot/network/utils.go 58.33% <0.00%> (ø)
dot/network/notifications.go 65.29% <0.00%> (+0.11%) ⬆️
lib/grandpa/network.go 47.79% <0.00%> (+0.38%) ⬆️
lib/blocktree/blocktree.go 54.71% <0.00%> (+1.08%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d2da7fb...14a0f83. Read the comment docs.

func ImportsNodeRuntime() (imports *wasm.Imports, err error) {
imports = wasm.NewImports()

for _, toRegister := range []struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be more clear to have this as a fixed-sized array outside of the function scope IMO

var importedFuncs = [...]struct{
  import_name string
  implementation interface{}
  cgoPointer     unsafe.Pointer
}{
    ...
}

for _, toRegister := importedFuncs {
    _, err = imports.AppendFunction(toRegister.importName, toRegister.implementation, toRegister.cgoPointer)
    if err != nil {
        return nil, fmt.Errorf("importing function: %w", err)
    }
}

Copy link
Contributor Author

@qdm12 qdm12 Jul 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely taking the fixed size array (god damn second time I don't use it, thanks for the reminder!).
Although I don't really see the point to have it at global scope 🤔 I don't think it would change performance wise, and it's only used in that function. It would also pollute more the (unexported) package Go API.

Keep in mind I'm a very pro-local-everything-activist

@qdm12 qdm12 merged commit 8fd2188 into development Jul 11, 2022
@qdm12 qdm12 deleted the qdm12/wasmer/append-loop branch July 11, 2022 12:57
@github-actions
Copy link

🎉 This PR is included in version 0.7.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

3 participants