mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
console: decompress JS libraries during init
This speeds up geth startup by 5ms because the asset is only loaded when the console used instead of loading it unconditionally during package init time.
This commit is contained in:
parent
77b900767c
commit
3ee39f28d1
2 changed files with 5 additions and 8 deletions
|
|
@ -30,6 +30,7 @@ import (
|
||||||
|
|
||||||
"github.com/dop251/goja"
|
"github.com/dop251/goja"
|
||||||
"github.com/ethereum/go-ethereum/internal/jsre"
|
"github.com/ethereum/go-ethereum/internal/jsre"
|
||||||
|
"github.com/ethereum/go-ethereum/internal/jsre/deps"
|
||||||
"github.com/ethereum/go-ethereum/internal/web3ext"
|
"github.com/ethereum/go-ethereum/internal/web3ext"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
"github.com/mattn/go-colorable"
|
"github.com/mattn/go-colorable"
|
||||||
|
|
@ -181,10 +182,12 @@ func (c *Console) initConsoleObject() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Console) initWeb3(bridge *bridge) error {
|
func (c *Console) initWeb3(bridge *bridge) error {
|
||||||
if err := c.jsre.Compile("bignumber.js", string(jsre.BignumberJs)); err != nil {
|
bnJS := string(deps.MustAsset("bignumber.js"))
|
||||||
|
web3JS := string(deps.MustAsset("web3.js"))
|
||||||
|
if err := c.jsre.Compile("bignumber.js", bnJS); err != nil {
|
||||||
return fmt.Errorf("bignumber.js: %v", err)
|
return fmt.Errorf("bignumber.js: %v", err)
|
||||||
}
|
}
|
||||||
if err := c.jsre.Compile("web3.js", string(jsre.Web3Js)); err != nil {
|
if err := c.jsre.Compile("web3.js", web3JS); err != nil {
|
||||||
return fmt.Errorf("web3.js: %v", err)
|
return fmt.Errorf("web3.js: %v", err)
|
||||||
}
|
}
|
||||||
if _, err := c.jsre.Run("var Web3 = require('web3');"); err != nil {
|
if _, err := c.jsre.Run("var Web3 = require('web3');"); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -28,12 +28,6 @@ import (
|
||||||
|
|
||||||
"github.com/dop251/goja"
|
"github.com/dop251/goja"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/internal/jsre/deps"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
BignumberJs = deps.MustAsset("bignumber.js")
|
|
||||||
Web3Js = deps.MustAsset("web3.js")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// JSRE is a JS runtime environment embedding the goja interpreter.
|
// JSRE is a JS runtime environment embedding the goja interpreter.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue