Comments (5)
This is now implemented as the store (see also the release announcement).
from sudbury.
So I took a jab at implementing this. In the following screenshot you can see the performance differences. The performance is encoding/decoding 10000 random Wire Packages (with 20-200 bytes payload evenly distributed in microseconds). I put map id
in there as well to give an idea of the cost of traversing the entire structure and forcing it to normal form.
from sudbury.
The Storable interface was implemented like this for the benchmark:
toInt :: Integral a => a -> Int
toInt = fromInteger . toInteger
{-# INLINE toInt #-}
instance Store WirePackage where
size = VarSize $ toInt . wirePackageSize
poke (WirePackage sen size op pl) = do
poke sen
poke op
poke size
let (sourceFp, sourceOffset, sourceLength) = B.toForeignPtr pl
pokeFromForeignPtr sourceFp sourceOffset sourceLength
peek = do
sen <- peek
op <- peek
size <- peek
let payloadSize = toInt size - 8
pl <- peekToPlainForeignPtr "Data.ByteString.ByteString" payloadSize
return $ WirePackage sen size op (B.PS pl 0 payloadSize)
{-# INLINE size #-}
{-# INLINE peek #-}
{-# INLINE poke #-}
This implementation is largely derived from the implementation of ByteString
in Store
itself.
Before I can write a PR implementing this in Sudbury itself, I have a couple of things that need to be discussed:
-
It might be nice to derive
Generic
onWirePackage
s and other applicable data structures as that allows a variety of useful classes to be used (likeNFData
). Probably more relevant for things that actually get exposed for the users. -
The implementation uses internals from
ByteString.Internal
. This module is "unsafe", and thus breaks the Safe pragmas. Is there a obvious solution to this? I'm not too familiar with the Safe pragmas. -
What does the Wayland protocol require with regards to Endianness? The people from Store were talking about implementing store in such a way that it will always write to Little Endian ByteString format (from both LE and BE machines). Is this desirable?
-
Any ideas for more interesting tests than
decodeEx . encode == id
-
Is there a more idiomatic approach to
toInt
😞
from sudbury.
This is really nice.
I'll respond quickly now and more thoroughly later, so that I'm not holding you up:
- I'd like to err on the side of caution wrt
Generic
andNFData
. When you need to do a full forcing of your objects explicitly, you're probably solving the wrong problem (I'd prefer an approach like the one taken here). But of course such instances are acceptable for benchmarks and tests. Note that you can add a "deriving instance" after the fact using theStandaloneDeriving
language extension. - The obvious solution is to stop using the safety pragmas as these are sort of deprecated anyway. Feel free to remove any safety pragma that gets in your way.
- The wayland wire protocol specifies that encoding is based on the host's encoding. I believe this is what
store
does anyway (but it'd be worth checking+documenting). - Well perhaps we could hard-code some sample packages, and package streams. I think the easiest way to record them is to use sudbury itself.
fromIntegral
is perhaps what you are looking for.
from sudbury.
StandaloneDeriving
is indeed what I was looking for, thanks!- Okay I'll be liberal in removing them
- I think they do indeed. There's currently this issue: mgsloan/store#31, where indeed HostEndianness is assumed.
- Alright, I think that might be worth doing in a separate PR (related to #2 I guess)
- Crap
I'll get started on the PR
from sudbury.
Related Issues (20)
- Version checks infrastructure
- Implement object lifetime tracker HOT 1
- Make project more inviting for developers HOT 2
- Status of sudbury HOT 3
- Build error when building against template-haskell-2.10.0.0 HOT 1
- v0.1.0.0 release preparations
- Use concurrent-extra's STM lock to lock the fd for reading/writing
- Setup ABI tracker
- Example code for a client HOT 5
- Commit access for cool contributions HOT 1
- Rewrite singleton data types HOT 1
- since field for enums HOT 1
- Extract the juices HOT 2
- C struct refactoring?
- Is this project dead HOT 3
- Weston sample clients don't run HOT 6
- Test suite HOT 2
- Add sudbury support to mesa? HOT 1
- Fix error handling HOT 1
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 sudbury.