Commit Graph

17 Commits

Author SHA1 Message Date
Yuya Nishihara
9b58e92dbe smartset: fix generatorset.last() to not return the first element (issue5609) 2017-06-27 23:50:22 +09:00
Yuya Nishihara
e199b8a6c1 smartset: fix default value of abstractsmartset.sort()
It's unused, but it shouldn't lie.
2017-06-25 00:14:48 +09:00
Martin von Zweigbergk
153a1c94b7 py3: catch StopIteration from next() in generatorset
IIUC, letting the StopIteration through would not cause any bugs, but
not doing it makes the test-py3-commands.t pass.

I have also diligently gone through all uses of next() in our code
base. They either:

 * are not called from a generator
 * pass a default value to next()
 * catch StopException
 * work on infinite iterators
 * request a fixed number of items that matches the generated number
 * are about batching in wireproto which I didn't quite follow

I'd appreciate if Augie or someone else could take a look at the
wireproto batching and convince themselves that the next(batchable)
calls there will not raise a StopIteration.
2017-06-20 14:00:41 -07:00
Yuya Nishihara
5db97a9276 smartset: micro optimize spanset.slice() to narrow range accordingly
-1ms isn't significant, but seems not bad.

  revset #0: limit(0:9999, 100, 9000)
  6) 0.001145
  7) 0.000214
  revset #3: last(0:9999, 100)
  6) 0.000197
  7) 0.000171
2015-04-10 00:14:16 +09:00
Yuya Nishihara
bd5f2e1677 smartset: micro optimize baseset.slice() to use slice of list
-1ms isn't significant, but seems not bad.

  revset #1: limit(0::9999, 100, 9000)
  5) 0.001681
  6) 0.000790
2015-04-09 23:56:06 +09:00
Yuya Nishihara
8dc3831c0a smartset: extract method to slice abstractsmartset
Sub classes can provide optimized implementations.
2015-03-24 00:14:53 +09:00
Yuya Nishihara
94f3c93476 smartset: extract spanset factory to make it constructed without a repo
This renames the spanset class to _spanset, and moves its __init__ to new
spanset() function. spanset() is now a factory function.

This allows us to construct a spanset without keeping a repo instance.
2015-05-24 11:07:14 +09:00
Yuya Nishihara
00575a85de smartset: change repr of spanset to show revisions as half-open range
Before, an empty spanset was displayed as '<spanset+ 0:-1>', which seemed
confusing.
2017-06-11 00:21:38 +09:00
Pulkit Goyal
9039b3baeb py3: use raw strings while accessing class.__dict__
The keys of class.__dict__ are unicodes on Python 3.
2017-04-28 01:13:07 +05:30
Gregory Szorc
5ca0f908bf py3: add __bool__ to every class defining __nonzero__
__nonzero__ was renamed to __bool__ in Python 3. This patch simply
aliases __bool__ to __nonzero__ for every class implementing
__nonzero__.
2017-03-13 12:40:14 -07:00
Yuya Nishihara
ec012a1a69 py3: use next() to obtain next item from inner generator of generatorset
.next attribute does not exist on Python 3. As this function seems to really
care about the overhead of the Python interpreter, I follow the way of micro
optimization.
2017-03-13 08:53:31 -07:00
Yuya Nishihara
51c8b96882 smartset: reorder initialization of baseset in more intuitive way
What we want to do is to assign either _set or _list per the given data
type.
2017-02-18 17:37:52 +09:00
Jun Wu
11f41ac7b5 smartset: preserve istopo for baseset operations
This is a follow-up of "smartset: use native set operations as fast paths".
It's more correct to just preserve the "istopo" information for "&" and "-"
operations, like what filteredset does.
2017-02-21 16:29:31 -08:00
Jun Wu
8b91946180 smartset: use native set operations as fast paths
For set operations like "&" and "-", where we know both basesets have their
sets ready, and the first set is sorted, use the native Python set
operations as a fast path.

Note: "+" is not optimized as that will break the ordering.

This leads to noticeable improvements on performance:

  revset                                | before | after | delta
  ----------------------------------------------------------------
  draft() & draft() & draft() & draft() |    776 |   477 | -39%
  draft() + draft() + draft() + draft() |   2849 |  2864 |
  draft() - draft() + draft() - draft() |    943 |   240 | -75%
  draft() - draft() - draft() - draft() |    557 |   197 | -64%

  (time measured in microseconds)
2017-02-18 17:23:43 -08:00
Jun Wu
5b7a815bb7 smartset: add some doctests
Add doctests explaining the set / list behavior. This will make the
following changes more confident.
2017-02-18 16:30:07 -08:00
Jun Wu
e5340d9f4b smartset: convert set to list lazily
If the caller only wants to construct a baseset via a set, and then do
"__contains__" tests. It's unnecessary to initialize the list.

Testing on my unfiltered hg-committed repo where len(draft()) is 2600, this
patch shows about 6% improvement on set intensive queries:

Before:

  $ for i in `seq 5`; hg perfrevset 'draft() & draft() & draft() & draft()'
  ! wall 0.001196 comb 0.000000 user 0.000000 sys 0.000000 (best of 2011)
  ! wall 0.001191 comb 0.000000 user 0.000000 sys 0.000000 (best of 2099)
  ! wall 0.001186 comb 0.010000 user 0.010000 sys 0.000000 (best of 1953)
  ! wall 0.001182 comb 0.000000 user 0.000000 sys 0.000000 (best of 2135)
  ! wall 0.001193 comb 0.000000 user 0.000000 sys 0.000000 (best of 2177)

After:

  $ for i in `seq 5`; hg perfrevset 'draft() & draft() & draft() & draft()'
  ! wall 0.001128 comb 0.000000 user 0.000000 sys 0.000000 (best of 2247)
  ! wall 0.001119 comb 0.000000 user 0.000000 sys 0.000000 (best of 2317)
  ! wall 0.001115 comb 0.000000 user 0.000000 sys 0.000000 (best of 2244)
  ! wall 0.001131 comb 0.000000 user 0.000000 sys 0.000000 (best of 2093)
  ! wall 0.001124 comb 0.000000 user 0.000000 sys 0.000000 (best of 2134)

It could have bigger impact on larger sets in theory.
2017-02-17 20:59:29 -08:00
Yuya Nishihara
2e50d5587f smartset: move set classes and related functions from revset module (API)
These classes are pretty large and independent from revset computation.

  2961 mercurial/revset.py
   973 mercurial/smartset.py
  3934 total

revset.prettyformatset() is renamed to smartset.prettyformat(). Smartset
classes are aliased since they are quite common in revset.py.
2016-10-16 17:28:51 +09:00