Giter Site home page Giter Site logo

Comments (4)

mccolljr avatar mccolljr commented on June 8, 2024

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.

cosmos72 avatar cosmos72 commented on June 8, 2024

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.

cosmos72 avatar cosmos72 commented on June 8, 2024

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.

123quant avatar 123quant commented on June 8, 2024

thanks for answer

go run将您的代码编译为本机可执行文件并运行它,但 Gophernotes 在后台使用解释器(gomacro,此包的自述文件中有一个链接)。在解释语言与运行本机可执行文件时,总会有一些减速。

话虽如此 - 共享一些特定代码可能会有所帮助,因为可能有办法将其更改为在 gophernotes 环境中更高性能

thanks for answer

from gophernotes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.