Comments (4)
go run
compiles your code to a native executable and runs that, but Gophernotes is using an interpreter under the hood (gomacro
, a link is in the README for this package). There is always going to be some amount of slowdown when interpreting a language vs. running a native executable.
Having said that - It may be helpful to share some specific code, since there could possibly be ways to change it to be more performant in the gophernotes environment
from gophernotes.
Go toolchain and standard library do not support (and actually makes really hard to) JIT-compile code at runtime and execute it.
I have tried that road, and desisted for several reasons:
- the garbage collector crashes if it finds a non-Go function running on the Go stack. You'd need to run JIT-compiled functions on the C stack (and switching stacks is slow).
- the garbage collector only knows about memory allocated by Go runtime (= Go memory), and will not scan for pointers the memory allocated by
malloc()
or other means (= C memory etc.). - the Go specs say you can store pointers to Go memory only in Go memory, and you can use them only from Go: you cannot store them in C memory, and you cannot use them in JIT-compiled code.
For these reasons, almost all Go interpreters use reflection to manipulate Go data structures, and the interpreted code is executed either as closures, as a bytecode interpreter, or (at worst) AST tree walking.
All these techniques have an overhead, and from some of my (old) benchmarks gophernotes and gomacro are among the fastest Go interpreters available, averaging to 10-100 times slower than compiled Go.
As @mccolljr pointed out, the speed depends a lot from the code you run:
in general, code dealing only with builtin types (bool, int*, uint*, float*, string) is quite fast, while using composite types (arrays, chans, maps, pointers, slices, structs) is relatively slow.
Note: there is an interpreter gijit that compiles Go source code to Lua. It's fast but has to to a lot of convolutions to manipulate Go data structures.
from gophernotes.
Update: imported packages are automatically compiled by gophernotes/gomacro using Go toolchain, and loaded as plugins (this works on Linux and Mac OS X only - unluckily on Windows the procedure is more convoluted).
So if there's a particular piece of code that your really need to be fast, you can for example:
import "github.com/my/package/full/path"
or even import it from a local filesystem path (useful in case the package is not published):
import "/my/package/absolute/path"
import "./my/package/relative/path"
import "../my/package/relative/path"
then use your favorite package from gophernotes, and it will be compiled to native code.
from gophernotes.
thanks for answer
go run
将您的代码编译为本机可执行文件并运行它,但 Gophernotes 在后台使用解释器(gomacro
,此包的自述文件中有一个链接)。在解释语言与运行本机可执行文件时,总会有一些减速。话虽如此 - 共享一些特定代码可能会有所帮助,因为可能有办法将其更改为在 gophernotes 环境中更高性能
thanks for answer
from gophernotes.
Related Issues (20)
- [Question] How to import third-party packages on Windows? HOT 1
- Docker image update? HOT 4
- Error `cannot convert type <*main.b> to interface <error>` on valid Go code HOT 3
- extra output? HOT 1
- Proposal: present Gophernotes at Golab 2022 (Italy) ? HOT 3
- stop notebook on error HOT 2
- Dockerfile build image fail autocomplete HOT 1
- Import `google.golang.org/grpc` fails HOT 2
- not a package: "n" in n.multiply <*ast.SelectorExpr> HOT 1
- gophernotes and replace on go.mod
- Running in VSCode using jupyter HOT 7
- External repo not working HOT 6
- reflect.Value.Convert: value of type reflect.Value cannot be converted to type http.FileSystem
- compile: version "go1.19.4" does not match go tool version "go1.20.2" # unicode/utf16 HOT 2
- Cannot use third party libraries HOT 5
- When will the docker image use jupyter lab?
- fails to import "sync" package HOT 1
- runtime error: index out of range HOT 1
- unimplemented type
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gophernotes.