More efficient ToJSON and FromJSON instances for tuples #48

Merged
merged 1 commit into from Nov 29, 2011

Conversation

Projects
None yet
3 participants
Collaborator

basvandijk commented Nov 26, 2011

toJSON previously converted a tuple into a list and then converted that list into a vector. I now run a ST computation that creates a mutable vector of the correct size and fills it with the right Values. This improves performance by 45%.

fromJSON previously converted the vector into a list and then pattern matched that list so that the elements could be parsed. I now index the vector directly so we don't need to create a list. This improved performance by 20%.

@basvandijk basvandijk More efficient ToJSON and FromJSON instances for tuples
toJSON previously converted a tuple into a list and
then converted that list into a vector.
I now run a ST computation that creates a mutable vector of the correct size
and fills it with the right Values.
This improves performance by 45%.

fromJSON previously converted the vector into a list and
then pattern matched that list so that the elements could be parsed.
I now index the vector directly so we don't need to create a list.
This improved performance by 20%.
1f235b4
Owner

bos commented Nov 26, 2011

I'll try to get to this in the next day or two, but I'm traveling, so there might be a delay. Thanks!

On Nov 26, 2011, at 6:46, Bas van Dijkreply@reply.github.com wrote:

toJSON previously converted a tuple into a list and then converted that list into a vector. I now run a ST computation that creates a mutable vector of the correct size and fills it with the right Values. This improves performance by 45%.

fromJSON previously converted the vector into a list and then pattern matched that list so that the elements could be parsed. I now index the vector directly so we don't need to create a list. This improved performance by 20%.

You can merge this Pull Request by running:

git pull https://github.com/basvandijk/aeson faster-tuples

Or you can view, comment on it, or merge it online at:

#48

-- Commit Summary --

  • More efficient ToJSON and FromJSON instances for tuples

-- File Changes --

M Data/Aeson/Types/Class.hs (70)
A benchmarks/AesonTuples.hs (45)

-- Patch Links --

https://github.com/bos/aeson/pull/48.patch
https://github.com/bos/aeson/pull/48.diff


Reply to this email directly or view it on GitHub:
#48

Collaborator

hvr commented Nov 29, 2011

@basvandijk nice... are you planning on porting this optimization over to the TH-generated instances? :-)

update: nevermind, I just saw the other pull-request C:-)

@bos bos added a commit that referenced this pull request Nov 29, 2011

@bos bos Merge pull request #48 from basvandijk/faster-tuples
More efficient ToJSON and FromJSON instances for tuples
042a6bc

@bos bos merged commit 042a6bc into bos:master Nov 29, 2011

Owner

bos commented Nov 29, 2011

Once again - thanks, @basvandijk!

@tolysz tolysz pushed a commit to tolysz/aeson that referenced this pull request May 18, 2015

@bos bos Merge pull request #48 from basvandijk/faster-tuples
More efficient ToJSON and FromJSON instances for tuples
eddbbf5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment