Commit Graph

140 Commits

Author SHA1 Message Date
Simon Marlow
493c42fa0f Handle exceptions correctly in async datasources
Reviewed By: zilberstein, niteria

Differential Revision: D4868473

fbshipit-source-id: 0daf35e23f7ca4e87c3316786f3ac7a8ee7148cf
2017-04-19 12:27:42 -07:00
Oleg Grenrus
6a218f9110 Allow aeson-1.2
Summary: Closes https://github.com/facebook/Haxl/pull/69

Differential Revision: D4897787

Pulled By: watashi

fbshipit-source-id: aa8cbcb52822b0a1a3d31112313f495fc11efe1c
2017-04-16 18:53:48 -07:00
Jonathan Coens
2bc00c77b1 Add vanilla stack.yaml file
Summary: Adds a simple `stack` file using the latest version of stackage.

Reviewed By: watashi

Differential Revision: D4843970

fbshipit-source-id: 938a16de769210661064157084f5eac42c7c0494
2017-04-07 14:04:02 -07:00
Oleg Grenrus
f3d340924c Bump more bounds
Summary:
- `binary-0.9` is accidental major jump and is now deprecated, I'm not sure what's best to do, cabal solver should pick `-0.8.x.y.` version
- `HUnit` and `time` changes do not affect use in haxl.
Closes https://github.com/facebook/Haxl/pull/68

Differential Revision: D4843906

Pulled By: JonCoens

fbshipit-source-id: b97c78e644a170745d7a29aab5c137e86f7018be
2017-04-06 10:18:42 -07:00
Simon Marlow
60f1c6b872 Add pOr and pAnd
Summary:
These two operators are subtly non-deterministic, but can potentially
improve performance significantly in cases where

* We don't want to use .|| because it's too sequential
* We don't want to use || because it forces us to do wasted work

(and equivalently for &&).

The implementation is a bit subtle, see Note [tricky pOr/pAnd]

Reviewed By: xich

Differential Revision: D4611809

fbshipit-source-id: 832ace29dfc44e48c14cc5d4f52a0114ee326c92
2017-02-27 09:19:51 -08:00
Simon Marlow
b5821182cf Fix the profile test in haxl-core-unit
Summary:
I didn't look into this too deeply but I'm guessing it was because the
constant expression had been lifted out, so I made it not a constant
expression.

Reviewed By: JonCoens

Differential Revision: D4521430

fbshipit-source-id: 687075d8486b38743b3bd8b9a9f26aa198b2d258
2017-02-08 01:32:25 -08:00
Oleg Grenrus
990b80cbc6 Test with GHC 8.0.2
Summary:
If this goes ok, can we have a release?
Closes https://github.com/facebook/Haxl/pull/66

Reviewed By: simonmar

Differential Revision: D4409114

Pulled By: niteria

fbshipit-source-id: 6d6e88f1cf7b9ae2d851eaa86966f2eb417b4d7e
2017-01-12 10:01:33 -08:00
Oleg Grenrus
d8f2eeed13 Allow vector-0.12, time-1.7; Drop unused directory
Summary: Closes https://github.com/facebook/Haxl/pull/65

Reviewed By: xich

Differential Revision: D4391469

Pulled By: niteria

fbshipit-source-id: d9a54fe6c4a255c0e82b26aca2849265fd7e8b53
2017-01-08 12:31:32 -08:00
Oleg Grenrus
d77b818a82 Allow aeson-1.1
Summary:
Alternatively we could change dependency to `aeson-compat`, which has less major version bumps (because it has smaller public API surface, yet one have to be careful .e.g. not to rely on instance implementations).
Closes https://github.com/facebook/Haxl/pull/64

Differential Revision: D4385525

Pulled By: xich

fbshipit-source-id: 72246e0f9144728e618de7bfcf983531bd3d281a
2017-01-05 17:01:26 -08:00
Zejun Wu
03d434fbd6 Include request in the uninitialized data source error
Summary:
Include request in the uninitialized data source error so we will
know which request is not in cache or triggering this problem.
This will increase the size of error message, but in production
this should not happen as we should sanitize data source is
initizlied correctly.

Reviewed By: codemiller

Differential Revision: D4342674

fbshipit-source-id: ec3506285806e749dccade5ba5eb8cfdb25a5671
2016-12-19 10:16:36 -08:00
Oleg Grenrus
b0a5f7b8a8 Rename Show1 to ShowP
Summary:
Resolve #62
Closes https://github.com/facebook/Haxl/pull/63

Reviewed By: JonCoens

Differential Revision: D4299180

Pulled By: niteria

fbshipit-source-id: 0bcbefd26184d1e7ad5de99a806ce0cf4b57d1a6
2016-12-09 14:31:39 -08:00
Bartosz Nitka
b8cb1d850f Bump version before release
Summary: Closes https://github.com/facebook/Haxl/pull/61

Reviewed By: darshankapashi

Differential Revision: D4222554

Pulled By: niteria

fbshipit-source-id: d634be076eef94c00277952e6c8bc1920b052f89
2016-11-22 14:16:26 -08:00
Bartosz Nitka
c3d650e173 Allow HUnit 1.5
Summary:
According to #1965:

> Stackage nightly builds will soon move to HUnit-1.5.
Closes https://github.com/facebook/Haxl/pull/60

Reviewed By: xich

Differential Revision: D4221036

Pulled By: niteria

fbshipit-source-id: d3b011c7510ab9eceed9a1afdce0e55ed0983cf0
2016-11-22 13:01:33 -08:00
Oleg Grenrus
bc791fd734 Allow HUnit-1.4
Summary: Closes https://github.com/facebook/Haxl/pull/59

Reviewed By: niteria

Differential Revision: D3987227

Pulled By: algoriddle

fbshipit-source-id: 3be85a3eef2f40fd0a0efe0aee09714646632b4f
2016-10-07 05:46:38 -07:00
Oleg Grenrus
f80fe801a2 Make haxl compile cleanly with stack build --pedantic
Summary: Closes https://github.com/facebook/Haxl/pull/56

Reviewed By: JonCoens

Differential Revision: D3973977

Pulled By: simonmar

fbshipit-source-id: 527e17407dbeb3376955733949b0edb8b581122a
2016-10-05 05:46:30 -07:00
Jonathan Coens
f5ecbea752 Drop NFData from Haxl Monad
Summary: `GenHaxl` having an `NFData` instance is apparently a lie. Remove this functionality

Reviewed By: simonmar

Differential Revision: D3967290

fbshipit-source-id: 1da91dcd6470de0f911e8a29b86c4aa5d6c7301f
2016-10-04 05:16:28 -07:00
Gergely Szilvasy
98b403f0a4 fix package
Summary: Some of the test files were not listed in haxl.cabal

Reviewed By: kuk0

Differential Revision: D3951346

fbshipit-source-id: 8e6677a728acde3713c618a6383b2de510b1ac86
2016-09-30 10:01:37 -07:00
Gergely Szilvasy
187bd49f54 increasing version in haxl.cabal
Summary: Increasing package version before uploading on hackage.

Reviewed By: JonCoens

Differential Revision: D3944387

fbshipit-source-id: 146ed68970b7d3d6486b0e10f7d183e60e37257b
2016-09-30 03:16:33 -07:00
Jonathan Coens
78052b9625 Derive NFData instance for GenHaxl
Summary: Having an NFData instance allows forcing calls that return a Haxl computation to run.

Reviewed By: xich

Differential Revision: D3906781

fbshipit-source-id: e49448152695383031af6d315a20dbcd1c10720c
2016-09-22 11:16:33 -07:00
Andrew Farmer
528bba5565 Add unit test to demonstrate withLabel with pure/haxl exceptions
Summary:
Labels which throw Haxl exceptions are recorded, but pure exceptions bubble up
and labels are lost. This test demonstrates this.

Reviewed By: simonmar

Differential Revision: D3672479

fbshipit-source-id: fab10878e7eb067e0c65bcf401d75604c333007f
2016-08-22 08:31:36 -07:00
Oleg Grenrus
bc4a25c61e Support aeson-1
Summary: Closes https://github.com/facebook/Haxl/pull/54

Reviewed By: kuk0

Differential Revision: D3696720

Pulled By: niteria

fbshipit-source-id: f04ba17a24a74dcc0de8b1c4336c59e28d5a427d
2016-08-10 08:16:40 -07:00
Andrew Farmer
8a69ddcc0d Import Control.Applicative in MemoizationTests for GHC < 7.10
Summary: GHC prior to 7.10 didn't export <$> in the prelude.

Reviewed By: watashi

Differential Revision: D3659220

fbshipit-source-id: af95574bc33f593fe0deb9217a963a7d9d9b0a16
2016-08-02 20:16:33 -07:00
Andrew Farmer
69ede7d79d Import Control.Applicative in Haxl.Core.Memo for GHC 7.8 support
Summary: Prior to GHC 7.10, <$> was not in the prelude, so requires an explicit import.

Reviewed By: watashi

Differential Revision: D3656379

fbshipit-source-id: 43925bc9c483ee712b04976d6fa6cb6b9d9b998e
2016-08-02 11:17:01 -07:00
Andrew Farmer
1ca0643c10 Add travis build status badge to readme
Summary:
The 7.8 build keeps breaking, but no one notices until someone opens an issue.
With the travis badge, breakage will at least be visible from the github
landing page for Haxl repo.

Reviewed By: zilberstein

Differential Revision: D3656468

fbshipit-source-id: 5537ab78b9dd44a5a3f07e7e3db7f73ec959f096
2016-08-02 10:46:36 -07:00
Andrew Farmer
c34ea3a3fd Expose MiddleException for access to eName function.
Summary: Expose MiddleException because the `eName` function is useful.

Reviewed By: watashi

Differential Revision: D3635507

fbshipit-source-id: bec3fac0b4f7c009c57d14857d46576ffc5ab826
2016-07-28 09:31:28 -07:00
Kubo Kovac
10623dc6ee add show instances for core types
Summary: add show instances for core types

Reviewed By: JonCoens

Differential Revision: D3613250

fbshipit-source-id: aa3bacdbb938666352859078ccf93fc24f3e8652
2016-07-25 15:46:29 -07:00
P. C. Shyamshankar
3cc0b3e054 Add 1-ary and 2-ary function memoization machinery
Summary:
This revision generalizes the existing memoization framework to 1-ary and 2-ary
functions (namely functions of type (a -> GenHaxl u b) and (a -> b _> GenHaxl u c)).

For every support arity (currently 0, 1, and 2), a family of functions {
newMemoWithX, prepareMemoX and runMemoX } are provided. newMemo itself is
generic across all arities.

Reviewed By: simonmar

Differential Revision: D3555791

fbshipit-source-id: 010a9889d42327607c8b03a5f7a609ee0c70de49
2016-07-25 06:16:28 -07:00
Kubo Kovac
d7483ccf6b fix haddock
Summary: fix code examples in haddock

Reviewed By: sykora

Differential Revision: D3605259

fbshipit-source-id: ff7bfa1cb6a1d592967c9b69ac5e37de95d1b502
2016-07-22 07:16:27 -07:00
P. C. Shyamshankar
bff7b643f5 Refactor cachedComputation to use newMemo/runMemo.
Summary:
This revision refactors cachedComputation to only contain logic relevant to
where the request-scope memo lives; memo creation and running logic is delegated
to newMemo(with) and runMemo.

Comments in cachedComputation have been moved over to newMemo/runMemo, and a
benchmark for cachedComputation has been added to monadbench. Surprisingly,
performance might have improved, albeit very slightly.

Reviewed By: simonmar

Differential Revision: D3514791

fbshipit-source-id: b2f0627824adc79b766e4f4e28c4af957ff00a00
2016-07-06 03:31:25 -07:00
Simon Marlow
549c14fb26 Track stack traces of dataFetch calls when profiling
Summary: This diff collects the stack traces of `dataFetch` calls, when `reportLevel` >= 5 and profiling is on.  Zero overhead for non-profiled code.

Reviewed By: niteria

Differential Revision: D2535947

fbshipit-source-id: fd43c20edd5455bd5e41113059fc69206b998e44
2016-07-05 02:31:24 -07:00
P. C. Shyamshankar
7cd98c4076 Add createMemo/updateMemo helpers, with monadbench test-case.
Summary:
This diff adds the createMemo and updateMemo helper functions, which abstract
the memoization reference management logic of cachedComputation. This separates
the work of *how* a memoized computation is created/updated, from *where* the
memo reference lives, allowing the same code to be used to manage request-scope
and feature-scope memos simultaneously.

A refactor of cachedComputation to use this abstraction is forthcoming.

Reviewed By: simonmar

Differential Revision: D3492803

fbshipit-source-id: 9dadd3860d5bec3bf776eef7c1bd610c25283729
2016-07-01 08:31:28 -07:00
Jonathan Coens
3d14694b22 Add allocation statistics per data source per round
Summary: Track and report allocation usage for data sources and rounds

Reviewed By: simonmar

Differential Revision: D3488169

fbshipit-source-id: 39c853ec89881e9f7d8d32b1a8d0a878c847a33e
2016-06-28 03:01:27 -07:00
Katie Ots
f1256b6ae7 Improve clarity in Haxl documentation
Summary: Improve clarity in Haxl documentation

Reviewed By: niteria

Differential Revision: D3462720

fbshipit-source-id: e73f149b05b87ea10ef43f051f88a269ca91ca66
2016-06-21 05:31:32 -07:00
Jon Coens
3a88f2a088 Merge pull request #50 from adarqui/typo
Just a typo fix
2016-06-21 09:13:19 +01:00
Andrew Darqui
a90363a03c typo fix 2016-06-21 02:48:30 -04:00
P. C. Shyamshankar
a7b3552d5c Add memoization benchmarks to monadbench
Summary:
Memoized operations were not represented in monadbench, this diff fixes that. Three tests are included:

1. Unmemoized computation, repeated N times.
2. Memoized computation, repeated N times.
3. Memoized computation, repeated N times **under different memo keys**

Reviewed By: simonmar

Differential Revision: D3444238

fbshipit-source-id: b2df534232acd5c02f9f6aea030c55d5cc846eb0
2016-06-20 02:46:24 -07:00
P. C. Shyamshankar
43f95ee605 Add memoHits to sigma profiling framework.
Summary: Integrate counts of memoized computation access into the profiling framework. Every call to `cachedComputation` logs one hit, including the first one.

Reviewed By: simonmar

Differential Revision: D3430491

fbshipit-source-id: a799c0e603c7bc94813da9801d7f4931a011131d
2016-06-15 03:31:34 -07:00
Andrew Farmer
922717e736 Add :profile command
Summary:
Add a :profile command to haxlsh to view lightweight profiling data.
Has optional flags to sort output on a given column, or filter rows by name
with a regex.

Useful for iterating while trying to squash allocation issues.

Differential Revision: D3429989

fbshipit-source-id: 3631afbac6f7a8580b1c46fae8039bacaa996ab3
2016-06-14 09:17:25 -07:00
Gergely Szilvasy
251ad5c3e5 Version bounds on binary package
Summary:
Putting version bounds on binary package in haxl.cabal
Closes https://github.com/facebook/Haxl/pull/48

Reviewed By: watashi

Differential Revision: D3371245

Pulled By: algoriddle

fbshipit-source-id: 574cbbe3ee081bd4e8af7c91fa89cf6ab6a03029
2016-06-07 15:16:29 -07:00
Gergely Szilvasy
4c5a07b98f Fix compilation error on 7.8.4 due to missing import
Summary: Adding missing import

Reviewed By: xich

Differential Revision: D3390552

fbshipit-source-id: 0a083bb9612f2923207880b813f10bf471af1497
2016-06-05 03:34:29 -07:00
Gergely Szilvasy
1893551564 Unbreak cabal test
Summary: Some tests were failing, but we ignored the test failures by not checking the return value from the test runner. This patch fixes both the test runner and the tests.

Reviewed By: watashi

Differential Revision: D3379609

fbshipit-source-id: 0a1278879faa5beb0f9779ddfaa622cdbf05a73f
2016-06-04 15:31:43 -07:00
Andrew Farmer
9d5db2ae63 Optimize Haxl Monad
Summary:
This diff does two things:

1. Claws back performance lost to lightweight profiling, and then some.
Haxl monad with lightweight profiling is now faster than it was before
lightweight profiling was added.

par1 and tree are ~20% faster.
seqr is ~10% faster.
par2 and seql are unchanged.

2. Eliminate redundant constraints on some exported functions.
Wherever types on exported functions changed, they became less
constrained with no loss of functionality. Notably, the *WithShow
functions no longer require pointless Show constraints.

Now the gory details:

Monadbench on master (before lightweight profiling):

  par1
  10000 reqs: 0.01s
  100000 reqs: 0.11s
  1000000 reqs: 1.10s
  par2
  10000 reqs: 0.02s
  100000 reqs: 0.41s
  500000 reqs: 2.02s
  seql
  10000 reqs: 0.04s
  100000 reqs: 0.50s
  500000 reqs: 2.65s
  seqr
  200000 reqs: 0.02s
  2000000 reqs: 0.19s
  20000000 reqs: 1.92s
  tree
  17 reqs: 0.48s
  18 reqs: 0.99s
  19 reqs: 2.04s

After D3316018, par1 and tree got faster (surprise win), but par2 got worse, and seql got much worse:

  par1
  10000 reqs: 0.01s
  100000 reqs: 0.08s
  1000000 reqs: 0.91s
  par2
  10000 reqs: 0.03s
  100000 reqs: 0.42s
  500000 reqs: 2.29s
  seql
  10000 reqs: 0.04s
  100000 reqs: 0.61s
  500000 reqs: 3.89s
  seqr
  200000 reqs: 0.02s
  2000000 reqs: 0.19s
  20000000 reqs: 1.83s
  tree
  17 reqs: 0.39s
  18 reqs: 0.77s
  19 reqs: 1.58s

Looked at the core (-ddump-prep) for Monad module.
Main observation is that GHC is really bad at optimizing the 'Request r a' constraint because it is a tuple.

To see why:

  f :: Request r a => ...
  f = ... g ... h ...

  g :: Show (r a) => ...
  h :: Request r a => ...

GHC will end up with something like:

  f $dRequest =
    let $dShow = case $dRequest of ... in
    let $dEq = case $dRequest of ... in
    ... etc for Typeable, Hashable, and the other Show ...
    let g' = g $dShow ... in
    let req_tup = ($dShow, $dEq, ... etc ...) in
    h req_tup ...

That is, it unboxes each of the underlying dictionaries lazily, even though it only needs the single Show dictionary.
It then reboxes them all in order to call 'h', meaning none of the unboxed ones are dead code.
I couldn't figure out how to get it to do the sane thing (unbox the one it needs and pass the original dictionary onwards).
We should investigate improving the optimizer.

To avoid the problem, I tightened up the constraints in several places to be only what is necessary (instead of all of Request).

Notably:

Removed Request constraint from ShowReq, as it was completely unnecessary.
All the *WithShow variants do not take Show constraints at all. Doing so seemed to violate their purpose.
The crucial *WithInsert functions only take the bare constraints they need, avoiding the reboxing.
Since *WithInsert are used by *WithShow, I had to explicitly pass a show function in places.
See Note [showFn] for an explanation.

This gave us back quite a bit on seql, and a bit on seqr:

  par1
  10000 reqs: 0.01s
  100000 reqs: 0.08s
  1000000 reqs: 0.90s
  par2
  10000 reqs: 0.02s
  100000 reqs: 0.36s
  500000 reqs: 2.18s
  seql
  10000 reqs: 0.04s
  100000 reqs: 0.55s
  500000 reqs: 3.00s
  seqr
  200000 reqs: 0.02s
  2000000 reqs: 0.18s
  20000000 reqs: 1.73s
  tree
  17 reqs: 0.39s
  18 reqs: 0.79s
  19 reqs: 1.54s

Finally, addProfileFetch was getting inlined into dataFetchWithInsert.
This caused some let-bound stuff to float out and get allocated before the flag test.
Adding a NOINLINE prevented this, getting about 10% speedup on par2 and seql.
Doing the constraint work above enabled this, because otherwise the call to
addProfileFetches was creating the reboxing issue where it didn't exist before.

  par1
  10000 reqs: 0.01s
  100000 reqs: 0.08s
  1000000 reqs: 0.89s
  par2
  10000 reqs: 0.02s
  100000 reqs: 0.35s
  500000 reqs: 1.98s
  seql
  10000 reqs: 0.04s
  100000 reqs: 0.53s
  500000 reqs: 2.72s
  seqr
  200000 reqs: 0.02s
  2000000 reqs: 0.17s
  20000000 reqs: 1.67s
  tree
  17 reqs: 0.39s
  18 reqs: 0.82s
  19 reqs: 1.65s

Reviewed By: simonmar

Differential Revision: D3378141

fbshipit-source-id: 4b9dbe0c347f924805a7ed4c526c4e7c9aeef077
2016-06-04 15:20:42 -07:00
Andrew Farmer
b5a305b5c1 Count rounds/fetches for profiling labels.
Summary:
This collects the highest round in which a label adds a fetch, as well as
number of fetches per label per datasource. It reports these, along with
aggregated values with scuba sample of profiling data.

Aggregation for number of rounds is the maximum round of label or any of
label's children. Aggregation for number of fetches is sum.

Reviewed By: simonmar

Differential Revision: D3316018

fbshipit-source-id: 152690c7b8811d22f566437675c943f755029528
2016-06-04 15:20:42 -07:00
Gergely Szilvasy
19b024634b resolve test runner conflict
Summary: We use a FB-specific test runner in fbcode. As a result currently tests/Main.hs is different on github to allow 'cabal test' to pass. This diff resolves the difference by creating a common list of tests and two separate entry points for running the tests: tests/Main.hs for internal use, and tests/TestMain.hs for github. tests/Main.hs will (eventually) be excluded from the public sources.

Reviewed By: simonmar

Differential Revision: D3371609

fbshipit-source-id: 46a7382df814687230db43136acd496d0c5ebca9
2016-06-02 06:44:43 -07:00
Gergely Szilvasy
d7acb3421c Dummy get/setAllocationCounter for ghc < 7.10
Summary: Fix compilation errors since get/setAllocationCounter is not supported on ghc 7.8.4.

Reviewed By: xich

Differential Revision: D3371487

fbshipit-source-id: 33c41c12503b54eb7e4d82f1d987e089792b6a0f
2016-06-02 01:30:53 -07:00
P. C. Shyamshankar
2215e0bde0 Fix Haxl core/engine to work with -DEVENTLOG.
Summary:
Implementation of runHaxl gated behind -DEVENTLOG was slightly
bitrotted; this diff should fix that, and associated warnings and
errors.

Reviewed By: simonmar

Differential Revision: D3365756

fbshipit-source-id: 6632eff8fee29d431c1bc3cff55b74dc3ab0ae61
2016-06-02 01:30:53 -07:00
Gergely Szilvasy
c1638504d1 Add missing dependency in haxl.cabal
Summary: We use Data.Binary so the binary package is required for Haxl to build.

Reviewed By: niteria, kuk0

Differential Revision: D3365843

fbshipit-source-id: 4e1198a1d27dac91e6525fc163aaeb10f7a65972
2016-05-31 08:50:31 -07:00
Gergely Szilvasy
56612b9eba typo fix to eliminate fb and github diff 2016-05-31 08:08:55 -07:00
Simon Marlow
32eeb6879a Update haxl.cabal
Summary: We added a new module

Reviewed By: JonCoens

Differential Revision: D2254852

fbshipit-source-id: 223af03aeea4c1d24e098be70108d31cf0b3bb67
2016-05-31 07:25:22 -07:00
Zejun Wu
cf56b25aa5 Populate the number of failed data source requests to scuba
Summary:
This will be very helpful when investigating some bad requests or
infrastructure issues, especially when the exception is caught
by withDefault later so we cannot see them in sigma_feature_errors.

The cost is negligible, so

whynot

Reviewed By: simonmar

Differential Revision: D2548503

fbshipit-source-id: 8167ef536d201923f80793aca298cc6c5dff92d1
2016-05-31 06:47:52 -07:00