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

reduce pressure on garbage collector #6

Open
q9f opened this issue Jan 30, 2020 · 0 comments
Open

reduce pressure on garbage collector #6

q9f opened this issue Jan 30, 2020 · 0 comments

Comments

@q9f
Copy link
Owner

q9f commented Jan 30, 2020

avoid Rlp::Util.binary_add's segmented IO operations

instead, make all methods have an overload write to an IO, and the other overload which returns Bytes just creates an IO::Memory and calls the other overload.

ref https://www.reddit.com/r/crystal_programming/comments/ev2xig/wrote_a_native_library_implementing_rlp_recursive/

def self.encode(anything)
  io = IO::Memory.new
  encode(anything, io)
  io.to_slice # maybe add dup here
end

def self.encode(b : Bytes, io)
  # encode b into io
end

# and so on for other types

ref https://github.com/crystal-lang/crystal/blob/47bdbaa4d1638c76137bfa12de86eac454a15908/src/object.cr#L94-L105

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

No branches or pull requests

1 participant