mruoss

mruoss

YMLR - Need help in metaprogramming for improving the deriving macro

Hey Community

Is there anybody out there with good skills in metaprogramming? I definitely have to read Chris McCord’s book at some point because I feel like I’m doing too much of what I don’t understand lately. :slight_smile:

I am one of the maintainers of YMLR - A Yaml Encoder for Elixir and have recently refactored the library to work with a protocol for the encoder. I took the inspiration from Jason but they have implemented their __deriving__ macro in the Jason.Encoder module in a much more performant way. If anybody out there feels up for the job and has some spare time, I’d really appreciate a pull request for the improvement of the __deriving__ macro in Ymlr.Encoder

Many thanks in advance,
Michael

Most Liked

kip

kip

ex_cldr Core Team

I’ve taken a look and while I don’t have the time to dedicate to a PR I can offer the following observations (which may already be totally obvious to you).

  1. Since the :only and :except lists need to be known at compile time you can process them in the macro, outside the quote block. That will certainly give you some performance improvement and make it easier to maintain as well.

  2. Most encoding tasks that result in a binary (string) gain material performance benefits in encoding first to iodata and then calling :erlang.iodata_to_binary/1 at the very end. That function uses very efficient kernel system calls to convert io vectors to binaries. File.write/2 and friends support iodata as a parameter do you don’t even have to do the last call yourself and in effect the File.write/2 call will stream the iodata to disc (not exactly how it works, but close enough).

Those are the two primary differences I see with the Jason implementation being very idiomatic macros techniques.

kip

kip

ex_cldr Core Team

Since that narrows the scope I’ll take a first pass at a PR for point (1) tomorrow my time. Don’t expect a finished product but at least enough for you to move forward. Hopefully gets you on your way at least.

mruoss

mruoss

Guess it’s reading the book then. :laughing:

Last Post!

mruoss

mruoss

Very much appreciated, thanks!

Where Next?

Popular in Discussions Top

CharlesO
Erlang :list.nth simple, but 1 - based nth(1, [H|_]) -> H; nth(N, [_|T]) when N > 1 -> nth(N - 1, T). Elixir Enum.at … coo...
New
AlexMcConnell
The reason that Rails is as popular as it is is because it’s very easy for relatively inexperienced developers to get a lot of work done....
588 20142 166
New
AstonJ
If so I (and hopefully others!) might have some tips for you :slight_smile: But first, please say which area you’re finding most challen...
New
lucaong
Hello Elixir and Nerves community, I have been working for a while on an open-source embedded key-value database for Elixir, that I call...
230 14403 124
New
tomekowal
Hey guys! I want to create a toy project that shows a chart of temperature over time and updates every 5 seconds. I feel LiveView is per...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
paulanthonywilson
I like Umbrella projects and pretty much always use them for personal Elixir stuff, especially Nerves things. But I don’t think this is ...
New

Other popular topics Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49266 226
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New

We're in Beta

About us Mission Statement