1. 12 Oct, 2012 6 commits
    • Philip Pronin's avatar
      SpinLockArray · 992f3b81
      Philip Pronin authored
      Summary:
      Array of spinlocks where each one is padded to prevent false
      sharing.
      
      Useful for shard-based locking implementations in environments where
      contention is unlikely.
      
      Test Plan: ran tests in 'common'
      
      Reviewed By: soren@fb.com
      
      FB internal diff: D582149
      992f3b81
    • Andrei Alexandrescu's avatar
      Better unsigned to string conversion · 43bdc5d7
      Andrei Alexandrescu authored
      Summary:
      In https://phabricator.fb.com/D511928 Brian mentioned the current API for string append is insufficient for appending to a buffer. That made me curious about the relative performance of classic and table-based number to ASCII conversions.
      
      The results were interesting as on the average (over all digit lengths) the table-based conversion was faster, but performance was lackluster (in the worst case half as fast as the classic implementation) for large numbers, I presume due to the cache misses incurred by the tables.
      
      This diff proposes an improved unsigned-to-ASCII primitive that is much faster than both table-based (previous Folly) and classic primitive. The key is a fast digits10() implementation that precomputes the space required by the conversion. After that, the digits are issued in place, no more reverse required. The new routine is up to 14x faster than the classic implementation, depending on the number of digits (benchmarks in comments).
      
      Adding a few people who may be interested in the matter. Brian, thanks for bringing this matter up; if this gets in you may want to use the folly routine in proxygen.
      
      Test Plan: unittest and benchmarks.
      
      Reviewed By: simpkins@fb.com
      
      FB internal diff: D515572
      43bdc5d7
    • Jeremy Lilley's avatar
      Fix push_back() to shared fbstring bug. · 3a5767e7
      Jeremy Lilley authored
      Summary:
      The following asserts:
      fbstring str(1337, 'f');
      fbstring cp = str;
      cp.push_back('f');
      
      This is problematic since ml_.capacity() != capacity() inside fbstring_core
      for shared strings, which causes us not to un-share prior to push_back.
      
      Test Plan: Existing tests, add unittest case.
      
      Reviewed By: tudorb@fb.com
      
      FB internal diff: D580267
      3a5767e7
    • Lucian Grijincu's avatar
      folly: Range: implement find_first_of and optimize qfind(Range, char) · 0010b30e
      Lucian Grijincu authored
      Summary:
      implement ##find_first_of## and optimize ##Range.find(char)##
      
      ============================================================================
      folly/test/RangeBenchmark.cpp                   relative  time/iter  iters/s
      ============================================================================
      LongFindSingleCharDirect                                     2.76ms   362.63
      LongFindSingleCharRange                           15.88%    17.37ms    57.58
      ShortFindSingleCharDirect                                   53.41fs   18.72T
      ShortFindSingleCharRange                           0.00%    29.22ns   34.22M
      ============================================================================
      
      Test Plan:
      - added new tests
      
      - ran all folly tests
      
      fbconfig -r folly/ && mkk runtests_opt
      
      Reviewed By: tudorb@fb.com
      
      FB internal diff: D576720
      0010b30e
    • Rajat Goel's avatar
      Syntactic sugar · 4e745261
      Rajat Goel authored
      Summary: This makes code easy to read for eyes used to unique/shared ptrs.
      
      Test Plan: unit-tests
      
      Reviewed By: delong.j@fb.com
      
      FB internal diff: D575997
      4e745261
    • John Fremlin VII's avatar
      add pop_back to arrays · b9836f4a
      John Fremlin VII authored
      Summary: Add a pop_back() function to dynamic arrays.
      
      Test Plan: - used it
      
      Reviewed By: delong.j@fb.com
      
      FB internal diff: D569440
      b9836f4a
  2. 17 Sep, 2012 12 commits
    • Anton Likhtarov's avatar
      folly/SmallLocks.h compiler warning · d0dd99c7
      Anton Likhtarov authored
      Summary: Couldn't get an HPHP extension to compile against this
      
      Test Plan: compiled HPHP including folly/dynamic.h
      
      Reviewed By: delong.j@fb.com
      
      FB internal diff: D574364
      d0dd99c7
    • Tudor Bosman's avatar
      Verbosify exception tracer dumps · 6b4082ec
      Tudor Bosman authored
      Test Plan: by hand
      
      Reviewed By: philipp@fb.com
      
      FB internal diff: D570233
      6b4082ec
    • Fan Guo's avatar
      support -nan in conversion · 78ee2805
      Fan Guo authored
      Summary:
      Folly supports -inf and nan but not -nan, instead it raised unexpected exceptions not handled in the upstream.
      
      This diff is separated out from D569816 -- Diff1.
      
      Test Plan: std::isnan(folly::to<double>(-nan))
      
      Reviewed By: tudorb@fb.com
      
      FB internal diff: D569939
      78ee2805
    • Tudor Bosman's avatar
      Fix InpuByteStreamSplitter in debug mode. · 8a64dcbd
      Tudor Bosman authored
      Test Plan: stream_test, exception_tracer_test
      
      Reviewed By: soren@fb.com
      
      FB internal diff: D569476
      8a64dcbd
    • Philip Pronin's avatar
      Histogram function to write tab-separated values. · ad8e104a
      Philip Pronin authored
      Summary: Export histograms in a tab-separated format.
      
      Test Plan: Used it.
      
      Reviewed By: lucian@fb.com
      ad8e104a
    • Tudor Bosman's avatar
      Minor huge pages library changes · 6ea306c4
      Tudor Bosman authored
      Summary:
      Moved to separate library instead of :io
      Got rid of the mode argument when creating files -- umask is your friend
      Separated getSize interface from create
      Added FsUtil.h for some fs::path operations
      Switched some interfaces to fs::path instead of string / StringPiece
      Canonicalize paths so we don't care whether paths are absolute or
      relative
      
      Test Plan: fs_util_test, by hand
      
      Reviewed By: philipp@fb.com
      
      FB internal diff: D564465
      6ea306c4
    • Tudor Bosman's avatar
      Huge page library. · 569f5f14
      Tudor Bosman authored
      Test Plan: by hand
      
      Reviewed By: lucian@fb.com
      
      FB internal diff: D555164
      569f5f14
    • Lucian Grijincu's avatar
      fix build on: define own version of ALLOCM_LG_ALIGN · f2f512b4
      Lucian Grijincu authored
      Summary:
      On --platform=gcc-4.6.2-glibc-2.13-fb the build would fail because
      
      fbcode/third-party/gcc-4.6.2-glibc-2.13-fb/libgcc/libgcc-4.6.2/b4e37bb/include/c++/4.6.2/bits/basic_fbstring_malloc.h
      
      defines it's own version of ALLOCM_SUCCESS & co., but not ALLOCM_LG_ALIGN :(
      
      The '#ifdef ALLOCM_SUCCESS' check in 'folly/Malloc.h' would pass even
      though we didn't include jemalloc.
      
      Test Plan: build it
      
      Reviewed By: philipp@fb.com
      
      FB internal diff: D562273
      f2f512b4
    • Tudor Bosman's avatar
      Unbreak build. · 3dd18cd9
      Tudor Bosman authored
      Summary: I'll pretend you reviewed this.
      
      Test Plan: build
      
      Reviewed By: simpkins@fb.com
      
      FB internal diff: D562255
      3dd18cd9
    • Tudor Bosman's avatar
      Move exception tracer library to folly/experimental · e8cabb32
      Tudor Bosman authored
      Summary:
      This change is mostly mechanical (moving files, changing include paths,
      etc).  I made some changes to TARGETS to make it easier for the library
      to be linked in (instead of LD_PRELOADed)
      
      Test Plan: by hand
      
      Reviewed By: simpkins@fb.com
      
      FB internal diff: D562196
      e8cabb32
    • Lucian Grijincu's avatar
      Add ALLOCM_LG_ALIGN to Malloc.h · b94353f2
      Lucian Grijincu authored
      Test Plan: .
      
      Reviewed By: soren@fb.com
      b94353f2
    • Tudor Bosman's avatar
      Stream operations: file access, iteration, splitting. · eed46f42
      Tudor Bosman authored
      Summary: Intended to complement and replace strings::byLine.
      
      Test Plan: stream_test
      
      Reviewed By: delong.j@fb.com
      
      FB internal diff: D463341
      eed46f42
  3. 26 Aug, 2012 22 commits
    • Tudor Bosman's avatar
      Fix fedora / ubuntu build · 39786ac6
      Tudor Bosman authored
      Test Plan: yes
      
      Reviewed By: andrewjcg@fb.com
      
      FB internal diff: D558628
      39786ac6
    • Adam Simpkins's avatar
      folly: simplify the stats avgHelper() function · 6bdcff46
      Adam Simpkins authored
      Summary:
      When the input type is a long double, perform division using long
      double.  In all other cases, divide using double precision.
      
      Also fix the EXPECT_EQ() usage in the test case.
      
      Test Plan: fbconfig -r common/stats folly && fbmake runtests
      
      Reviewed By: andrei.alexandrescu@fb.com
      
      FB internal diff: D555433
      6bdcff46
    • Adam Simpkins's avatar
      BucketedTimeSeries: fix type converison issues computing avg() · 14223eae
      Adam Simpkins authored
      Summary:
      D527040 had a bug in the code to compute the average: it incorrectly
      performed unsigned division when ValueType was a signed integer type.
      As a result, the average was reported incorrectly for stats with
      negative values.
      
      This makes the average code more intelligent when handling type
      conversions: if the caller wants a floating point value, or if the input
      type is floating point, floating point division is always returned.
      Otherwise, if the input is a signed type, signed integer division is
      performed.  Otherwise, unsigned integer division is performed.
      
      Test Plan: beholdunittests
      
      Reviewed By: lars@fb.com
      
      FB internal diff: D553583
      14223eae
    • Adam Simpkins's avatar
      folly: add a simple benchmark for Histogram::addValue() · 4f802227
      Adam Simpkins authored
      Summary:
      I wrote this an an example for the BENCHMARK_NAMED_PARAM() comments in
      D527040, and figured I might as well check it in as a real benchmark.
      
      Test Plan:
      Here's the output:
      
      ======================================================================
      folly/test/HistogramBenchmark.cpp         relative  time/iter  iters/s
      ======================================================================
      addValue(0_to_100)                                    15.43ns   64.81M
      addValue(0_to_1000)                                   15.45ns   64.70M
      addValue(5k_to_20k)                                   15.46ns   64.67M
      ======================================================================
      
      Reviewed By: rajat@fb.com
      
      FB internal diff: D552875
      4f802227
    • Shuai Ding's avatar
      change shared_ptr<>* to raw pointer · 51f060fe
      Shuai Ding authored
      Summary:
      change shared_ptr<>* to raw pointer in
      forwardIndex in RTIndex. This saves 16 bytes per
      forward list (decrease from 88 to 72) and translates
      to about 4-5% memory saving for RTIndex in ff tier.
      
      Test Plan: unit test
      
      Reviewed By: xliux@fb.com
      
      FB internal diff: D551191
      51f060fe
    • Adam Simpkins's avatar
      Add BucketedTimeSeries to folly · 4a7f5a25
      Adam Simpkins authored
      Summary:
      Add the BucketedTimeSeries class to folly.  This tracks time series
      counter data, using a circular buffer of buckets to expire old data
      points as time progresses.
      
      It supports querying the overall sum, count, average, and rate for the
      duration of the time series, as well as estimating these values for
      portions of the overall duration.
      
      Test Plan: Unit tests included.
      
      Reviewed By: andrei.alexandrescu@fb.com
      
      FB internal diff: D527040
      4a7f5a25
    • Philip Pronin's avatar
      one more simple folly::join optimization · 5df0c971
      Philip Pronin authored
      Summary:
      Before:
      
      _bin/folly/test/string_test --benchmark --bm_regex=join --bm_min_usec=1000000
      ============================================================================
      folly/test/StringTest.cpp                       relative  time/iter  iters/s
      ============================================================================
      joinCharStr                                                  3.59us  278.29K
      joinStrStr                                                   4.44us  225.09K
      joinInt                                                     10.55us   94.76K
      ============================================================================
      
      And after:
      
      _bin/folly/test/string_test --benchmark --bm_regex=join --bm_min_usec=1000000
      ============================================================================
      folly/test/StringTest.cpp                       relative  time/iter  iters/s
      ============================================================================
      joinCharStr                                                  3.61us  277.01K
      joinStrStr                                                   3.77us  264.97K
      joinInt                                                      9.92us  100.81K
      ============================================================================
      
      Test Plan: unittests, benchmark
      
      Reviewed By: tudorb@fb.com
      
      FB internal diff: D552364
      5df0c971
    • Tudor Bosman's avatar
      Add Bob Jenkins's SpookyHash to folly. · ff25e3b5
      Tudor Bosman authored
      Summary:
      http://burtleburtle.net/bob/hash/spooky.html
      The code is in the public domain, so republishing it as such is fine.
      The code needed modifications (the test was designed to run on Windows
      only; removed unhygienic typedefs; moved to folly::hash namespace)
      
      Also updated Makefile.am files.
      
      Test Plan: test added
      
      Reviewed By: soren@fb.com
      
      FB internal diff: D549572
      ff25e3b5
    • Michael Curtiss's avatar
      isPowTwo · ce15293f
      Michael Curtiss authored
      Summary:
      a la Hacker's Delight.
      
      Also, fix nonsensical nextPowTwo benchmark.
      
      Test Plan: Added test and benchmark.
      
      Reviewed By: tudorb@fb.com
      
      FB internal diff: D551510
      ce15293f
    • Philip Pronin's avatar
      one more folly::join overload · 2bfec0de
      Philip Pronin authored
      Summary: To allow codemod changes.
      
      Test Plan: ran test
      
      Reviewed By: tudorb@fb.com
      
      FB internal diff: D549516
      2bfec0de
    • Lee Hwa's avatar
      Task #906853: Implement ThreadLocalServiceData and reduce lock contentions... · 43c97295
      Lee Hwa authored
      Task #906853: Implement ThreadLocalServiceData and reduce lock contentions during channel counter update
      
      Summary:
      Cache the counter updates on thread local data structures and aggregate/publish
      the data from a separate thread periodically. The ThreadLocalServiceData is
      implemented on top of the TLStats data structures.
      
      I am plannig to deploy a private build to production tomorrow to test this
      change in production, but figured it might be better to send the diff out first
      and get code review feedbacks at the same time.
      
      Test Plan: Run and pass unit tests. Run end-to-end testings on sandbox. (TBD)
      Deploy a private build to a production server and make sure the thrift call
      latency is reduced.
      
      Reviewed By: xin@fb.com
      
      FB internal diff: D540239
      
      43c97295
    • Sergey Doroshenko's avatar
      folly: randomNumberSeed should be random wrt multiple threads · 68a546c7
      Sergey Doroshenko authored
      Summary:
      Right now, it relies on process id rather than on thread id. Thus, it can
      return the same seed when called from multiple threads over really short
      period of time, and these unlucky threads will end up with identical "random"
      sequences.
      
      Test Plan: newly added test fails against trunk, passes against changes in the diff
      
      Reviewed By: tudorb@fb.com
      
      FB internal diff: D548129
      68a546c7
    • Philip Pronin's avatar
      strings join · f3f96c69
      Philip Pronin authored
      Summary: The same interface as ##facebook::strings::join##, but few times faster.
      
      Test Plan: folly/test/StringTest.cpp
      
      Reviewed By: tudorb@fb.com
      
      FB internal diff: D548863
      f3f96c69
    • Nicholas Ormrod's avatar
      Added dynamic::convertTo<Type> method · 5b67454f
      Nicholas Ormrod authored
      Summary: convert a dynamic to a well-typed object
      
      Test Plan: run test file
      
      Reviewed By: delong.j@fb.com
      
      FB internal diff: D517021
      5b67454f
    • Nitay Joffe's avatar
      Add exception_tracer · 37f0ea54
      Nitay Joffe authored
      Summary: script to wrap gateway to run it with exception tracer.
      
      Test Plan: deploy
      
      Reviewed By: rajat@fb.com
      
      FB internal diff: D548147
      37f0ea54
    • Adam Simpkins's avatar
      folly: print nice time suffixes in benchmark output · efdc6894
      Adam Simpkins authored
      Summary: Print the times using "ms" for milliseconds, "us" for microseconds, etc.
      
      Test Plan:
      $ ./_bin/folly/test/benchmark_test
      ======================================================================
      folly/test/BenchmarkTest.cpp              relative  time/iter  iters/s
      ======================================================================
      bmFun                                                  3.36ns  298.01M
      bmRepeatedFun                                          1.76ns  569.38M
      ----------------------------------------------------------------------
      gun                                                    1.70ns  589.82M
      ----------------------------------------------------------------------
      baselinevector                                         3.08us  324.87K
      bmVector                                    13.64%    22.56us   44.32K
      ----------------------------------------------------------------------
      superslow                                               1.00s  999.82m
      ======================================================================
      
      Reviewed By: andrei.alexandrescu@fb.com
      
      FB internal diff: D546209
      efdc6894
    • Andrei Alexandrescu's avatar
      Fix debug build. · c14f40fc
      Andrei Alexandrescu authored
      Summary: Only tested in release mode, sigh. Fixed a failing asserd.
      
      Test Plan: tested in dbg mode
      
      Reviewed By: tudorb@fb.com
      
      FB internal diff: D546318
      c14f40fc
    • Andrei Alexandrescu's avatar
      Faster repeated append (particularly for short strings) · c3f47cdc
      Andrei Alexandrescu authored
      Summary:
      https://phabricator.fb.com/D544159 reveals a large performance gap between
      fbstring and std::string for repeated appends of short strings, which I
      consider a relatively urgent matter (as much of our code uses such patterns).
      
      This diff attempts to fix the issue in a principled manner by first appending
      the first character with exponential reallocation, after which the rest of the
      characters are appended normally.
      
      With the proposed fix the benchmarks are much faster than the previous fbstring
      and also than std::string (numbers to follow in comments).
      
      Test Plan: unittested and benchmarked
      
      Reviewed By: soren@fb.com
      
      FB internal diff: D545416
      c3f47cdc
    • Tudor Bosman's avatar
      sizeof works just as well as numeric_limits<T>::digits · 442e1c0c
      Tudor Bosman authored
      Summary: ... and is shorter and more readable
      
      Test Plan: folly/test
      
      Reviewed By: andrei.alexandrescu@fb.com
      
      FB internal diff: D545774
      442e1c0c
    • Nicholas Ormrod's avatar
      Increased std::vector compatibility of fbvector · bf188b34
      Nicholas Ormrod authored
      Summary:
      fbvector was not accepting move_iterators for
      InputIterator-templated construct, assign, and insert. The root cause
      was the check '(b_ <= &*first && &*first < e_)', used to check if the
      assignment was from internal data. This addressof check does not compile
      with rvalue-references, and causes the first iterator to be dereferenced
      more than once; both against the contract of std::vector. The standard
      allows for undefined behaviour in the self-iterator case, so there are
      no contractual barriers to removing this check.
      
      Test Plan:
      run fbvector test and benchmark. An fbgs for 'assign' turns
      up few matches; the seem to be normal use-case. Test fbvector assign
      with self-iterators in order (i.e. fbv.assign(fbv.begin(), fbv.end()));
      this seems to work fine.
      
      Reviewed By: andrei.alexandrescu@fb.com
      
      FB internal diff: D535012
      bf188b34
    • Tom Jackson's avatar
      Removing broken specialization of std::hash<std::tuple> · cc1518db
      Tom Jackson authored
      Summary: ^
      
      Test Plan: Unit tests
      
      Reviewed By: delong.j@fb.com
      
      FB internal diff: D543586
      cc1518db
    • Jeremy Lilley's avatar
      Add "short append" benchmark to fbstring benchmark suite. · be7be7e2
      Jeremy Lilley authored
      Summary:
      Appending many small strings to fbstring appears much slower (~3x) vs.
      std::string. Adding benchmark case to illustrate.
      
      [If this isn't wanted, I can revert]
      
      Test Plan: This is a benchmark.
      
      Reviewed By: soren@fb.com
      
      FB internal diff: D544159
      be7be7e2