Commit Graph

75 Commits

Author SHA1 Message Date
Ben Alpert
75ff12e984 Run fiber tests just once on Travis (#8221)
Consolidate facts tracking with the other script.
2016-11-07 11:43:29 -08:00
Ben Alpert
c4b9330f2a Hide detailed failure output in scripts/fiber/record-tests (#8214)
![image](https://cloud.githubusercontent.com/assets/6820/20033841/a55fefa4-a367-11e6-99c0-44dfe38e1db7.png)
2016-11-07 11:43:02 -08:00
Ben Alpert
84c57ddc6d Fix errors in ReactNativeMount (#8223) 2016-11-07 11:42:39 -08:00
Robin Ricard
33325ad009 [Fiber] Attempt to fix ReactDOMTextComponent test in Fiber (#8146)
* Attempt to fix ReactDOMTextComponent test in Fiber

Obviously, some tests pass but the reconciliation is still incomplete on this in Fiber.

Those changes just ignore reconciliation Comments while asserting (this fixes 2 tests already) but now shows that Fiber lacks some reconciliation features.

* Transmit a parentInstance to commitTextUpdate

This is done in case a Node#normalize() was performed on the parent instance and that the TextInstance got desolidarized from the parent. We provide the parent known by the parent Fiber to reattach the DOM node in this case.

* Added a more complex case around split nodes

This test does not assume one split node substitution alone but also some non-split nodes.

* Fiber supports split text nodes

This is done by suppressing nodes appearing during the split. this is based by comparing against the old value known by the Fiber.

* Simplify siblings cleaning in commitTextUpdate

No need to assert instanceof Text since the length comparator will work correctly.

* Ensure non-text nodes won't be removed

* Fix flow for Fiber Text reconciliation additions

Mostly define types as optionals. Respects the strict DOM API around Node & Element.

* Append at any stack stage only if necessary

The direct parent of the TextNode fiber may not contain the host node. We have to go through the hierarchy. However, since this work may be expensive, we only do it if absolutely necessary!

* Use tag & ReactTypeOfWork to find an HostComponent

* Addfailing scenario when running Node.normalize()

It happens when non-text-elements are added in the mix. @sebmarkbage seems to have an idea on how to fix it. This is just a repro of the bug!

* Register failing/passing fiber tests
2016-11-07 11:39:52 -08:00
Sebastian Markbåge
95334fada0 Track if SelectEventPlugin is attached on a per document basis (#8190)
This gets rid of the global flag on if something has listened to onSelect
and instead reads the isListening map if all the events are covered.
This is required if we want to attach events locally at roots.

Could be slower perf wise to handle events. An alternative solution would
be to attach a special flag on the listener map for the document so we
don't have to check the full dependency list.

However, my favorite solution would be to just eagerly attach all event
listeners (except maybe wheel). Then we don't have to do any of this stuff
on a per element basis.
2016-11-07 11:30:34 -08:00
Ben Alpert
f705adb599 Re-record tests 2016-11-05 14:59:22 -07:00
Ben Alpert
5f49b63bde Move setState callback to right after didUpdate (#8204)
It's much easier to do it this way in Fiber and there shouldn't be much observable difference.
2016-11-05 14:37:43 -07:00
Robin Ricard
ba6b53afba [Fiber] Complete ES6 Class related errors support (#8156)
* Print a warning in fiber for lacking render method

* Reject initial non-object state in Fiber

Rejects Arrays, Strings & Numbers. Allows nulls.

* Centralize fiber checks on ES6 Classes

* Add classic & instance property checks on fiber

- check the absence of getInitialState & getDefaultProps as methods
- check the absence of propTypes & contextTypes at instance-level

* Convert to normalized React `warning` calls

* Support lifecycle typo detection in fiber

* Get the complete warnings from the existing code

* Only check classInstance once

Avoid rechecking while resuming

* Can warn component while resuming but only once

This is achieved by tracking the warning state in the Fiber structure.

* Remove warning deduplication

* Factor name retrieval in a getName helper

* Use invariant instead of throw

* Read inst.state only once for the invariant

* Fix condition on the instance state

* Register failing/passing fiber tests
2016-11-05 11:19:48 -07:00
Dan Abramov
c80f390823 Make error handling more resilient
* Ensure that errors in one root don't prevent work on another root
* Fix an issue where boundary state change would get ignored in incremental mode
2016-11-04 23:35:50 +00:00
Andrew Clark
4266f08e48 [Fiber] "Task" priority for error boundaries and batched updates (#8193)
* Refactor scheduling functions and introduce Task priority

There was lots of duplication across all the scheduling functions. I
think we're far enough along that we can start trying to clean some
stuff up.

Also introduces a new priority level provisionally called Task priority.
This is for work that completes at the end of the current tick, after
the current batch of work has been committed. It's different from
Synchronous priority, which needs to complete immediately.

A full implementation of Task priority will follow. It will replace
the current batching solution.

* Implement Task priority

Task priority is similar to Synchronous priority. Both are flushed in
the current tick. Synchronous priority is flushed immediately (e.g. sync
work triggered by setState will flush before setState exits), where as
Task is flushed after the current batch of work is committed.

Currently used for batchedUpdates and nested sync updates. Task should
also be used for componentDidUpdate/Mount and error boundary work. I'll
add this in a later commit.

* Make error boundaries use Task Priority

I have all but one error fixed. Not sure how tricky the last one is,
but I'm cautiously optimistic. Pushing to show my current progress.

* Remove recursion from handleErrors

Changed the algorithm of handleErrors a bit to ensure that boundaries
are not revisited once they are acknowledged.

* Add incremental error boundary test

Discovered an edge case: a noop error boundary will break in incremental
mode unless you explicitly schedule an update.

* Refactor error boundaries in Fiber

* Simplify trapError() calls

The existing logic was written before we had a proper error handling system.

* Remove unnecessary flags

* Prevent performTaskWork recursion

* Be stricter about preventing recursion
2016-11-04 19:40:50 +00:00
Ben Alpert
f4a42b872b Fiber: Fix reconciling after null (#8202)
Before, this code was bailing out after encoutering a null child because it thought it was out of old children. Seen when reconciling [null, <span />, <Image />] with [null, <span />, <Image />] in XUISelector.
2016-11-03 23:56:29 -07:00
Dan Abramov
857672f7e7 Update passing tests 2016-11-03 14:41:39 +00:00
Andrew Clark
29dbbc31c9 UpdateQueue fixes
- Incorrect comparison when computing hasUpdate
- isReplace should be a property of the node, not the queue
2016-11-02 23:00:00 -07:00
Dan Abramov
c894679b75 [Fiber] Schedule animation regardless of deferred work (#8187)
* Remove comments about implementation details

* Schedule animation regardless of deferred work
2016-11-02 20:46:20 +00:00
Dan Abramov
eb674e47c8 [Fiber] Add tests for scheduling inside callbacks (#8186)
* Add tests for scheduling inside callbacks

* Don't test implementation details
2016-11-02 20:11:27 +00:00
Dan Abramov
95084bedbb Fix lint by removing unneeded type import 2016-11-02 12:45:15 -07:00
Andrew Clark
c3ab541e0f New effect type: Callback
This solves the problem I had with enqueueSetState and enqueueCallback
being separate.
2016-11-02 12:40:21 -07:00
Dan Abramov
2b26ea614d Fix the build (these tests were renamed) 2016-11-02 19:28:26 +00:00
Dan Abramov
99be3781ef [Fiber] Add more tests for scheduling (#8183)
* Add more tests for scheduling

* Remove ambiguous terms
2016-11-02 17:49:22 +00:00
Sebastian Markbåge
576542d0cf Handle the radio button case completely in the asap case (#8170)
Instead of scheduling individual callbacks to asap, we schedule one and
then do all the work in that one.

I'm doing this for architectural refactoring reasons.

Nevertheless, I'm adding a contrived unit test that this fixes. :)
2016-11-01 18:54:11 -07:00
Dan Abramov
1a49b5f563 [Fiber] Fix infinite loop in scheduler and add more tests (#8172)
* Make test more complete

* Add a failing test for scheduling in reverse order

It hangs forever because we don't clear next pointer when unscheduling a root. Therefore, when it's scheduled again, it brings all its previous chain with it, potentially creating a cycle.

* Clear the next pointer when unscheduling a root

Fixes a potential infinite cycle when we reschedule a root.

* Add new tests to Fiber test tracker
2016-11-01 17:44:57 +00:00
Ben Alpert
08b4cc53b8 Track passing/failing tests in fiber (#8169)
* Work around jest toEqual bug in ReactTreeTraversal

![image](https://cloud.githubusercontent.com/assets/6820/19879640/1cd7595a-9fb2-11e6-94ac-8c38bdfc90d3.png)

* Track passing/failing tests in fiber

Run scripts/fiber/record-tests to re-record, then check git diff to see what you changed.
2016-10-31 23:26:38 -07:00
Christopher Chedeau
dbd9c4b205 Introduce facts-tracker (#7747)
* Introduce facts-tracker

We want to be able to track various things like number of files that are flowified, number of tests passing with Fiber...

This introduces a tool that lets you do that. The API is very simple, you execute the script with a list of tuples [key value] and it's going to create a `facts` branch and put a txt file for each fact and values over time.

```
node scripts/facts-tracker/index.js \
  "flow-files" "$COUNT_WITH_FLOW/$COUNT_ALL_FILES"
```

Test Plan:
This is tricky to test because Travis only exposes the private variables (github token) when it processes a committed file and not on branches. The reason is that otherwise anyone could send a pull requests that does `echo $GITHUB_TOKEN` and steal your token.

Given this constraint, I did all the work using two of my repos:
- https://github.com/vjeux/facts-tracker
- https://github.com/vjeux/facts-tracker-test

and am sending this pull request that should work as is /fingers crossed/, but we won't be able to test it out until it is committed.

Note that once this lands, I'm going to kill those two repos.

* Update with all the suggested changes

* Branch on a flow type in travis.yml

* Use $GITHUB_TOKEN

* properly escape it
2016-09-26 12:58:51 -07:00
Dan Abramov
3fcba2044a Fix benchmarks (#7704) 2016-09-12 21:58:00 +03:00
Christopher Chedeau
334b8bdf16 I wrote it live! (#7663) 2016-09-06 15:18:42 -07:00
Christopher Chedeau
1a113a15c9 Update to jest 15
Jest 15 has just been released and is way more awesome: http://facebook.github.io/jest/blog/2016/09/01/jest-15.html

This pull request updates jest from version 12 to 15. Right now there's a fix in jest around Symbol that hasn't been released yet, so this will break CI and cannot be merged it. But once it ships by the end of the day, we'll be good to go :)

See comments inline for all the changes I've done.
2016-08-31 18:25:03 -07:00
Sebastian Markbåge
c06a68a10b Mock ReactDOM for Fiber Tests (#7206)
We currently write all our tests against the DOM implementation.
I need a way to run the Fiber tests against it. But I don't want
to take on any package dependencies on Fiber modules yet.

There's a problem with jest right now where you can't globally
mock modules that already exist. So I have to add a global call
to jest.mock.

Luckily we already have a way to test the useCreateElement paths
using a feature flag. I won't activate this flag in travis until
it passes, but the idea is to run all three variants in travis.

I'm not sure that invoking rAF and rIC synchronously is the best
way to test this since it doesn't capture the backwards
compatibility aspect. I.e. the fact that people might be relying
on the synchronous nature in real apps too. It's a start.

Ideally, jest would have these built-in.
2016-08-10 17:44:36 -07:00
Ben Alpert
e5513eceff Update benchmarks to be more realistic polymorphically (#7255)
Previously, the extract-components script would create the same number of layers of composites as the page it captures, but it would output a new class for each time any composite is used (since we don't want to replicate all the component logic).

I changed the script to output a single type for each type in the input -- and each generated component takes an index for which output it should return. This should be closer to how the original code behaves, especially with respect to VM function call lookups where the amount of polymorphism makes a difference.

I re-recorded the benchmarks with the new scripts. They run significantly faster:

```
Comparing old.txt (control) vs new.txt (test)
Significant differences marked by ***
% change from control to test, with 99% CIs:

* ssr_pe_cold_ms_jsc_jit
    % change: -41.73% [-43.37%, -40.09%]  ***
    means: 39.3191 (control), 22.9127 (test)
* ssr_pe_cold_ms_jsc_nojit
    % change: -44.24% [-46.69%, -41.80%]  ***
    means: 45.8646 (control), 25.5764 (test)
* ssr_pe_cold_ms_node
    % change: -45.61% [-47.38%, -43.85%]  ***
    means: 90.1118 (control), 49.0116 (test)
```

This is probably in part due to the changes here, but also the page I captured has changed somewhat in the meantime and there seem to be slightly fewer components in the hierarchy, so they're not really comparable. But going forward we can use this benchmark which should be more accurate. I also included an identical copy that uses stateless functional components so we can test optimizations to those later.
2016-07-12 19:32:51 -07:00
Keyan Zhang
1abce1630c Add reactProdInvariant and corresponding babel rewrite pass (#6948) 2016-06-07 17:11:04 -07:00
Ben Alpert
3c3c30a19a Fix function declaration in if statement (#6963)
Firefox doesn't like these and throws.
2016-06-04 13:37:57 -07:00
Keyan Zhang
bfd1531eca Add a gulp script for extracting error codes (#6882) 2016-06-01 11:21:26 -07:00
Paul O’Shannessy
d8a0b9a662 Upgrade to jest-cli@0.9 and use Jasmine2 2016-05-25 21:48:32 +01:00
Dmitrii Abramov
efb6d80e60 match jest.d.ts by regex 2016-05-19 19:24:40 -07:00
chico
655ac0f0dd update typescript 2016-05-19 19:24:40 -07:00
Ben Alpert
6afd51061a Embed JSX filename paths relative to repo root (#6778)
Test Plan: Changed the preprocessor to log the output of babel.transform and saw

```
var _jsxFileName = 'src/isomorphic/modern/element/__tests__/ReactJSXElementValidator-test.js';
```

in the resulting output, instead of an absolute path.
2016-05-16 11:15:12 -07:00
Ben Alpert
c0007d56e9 Interleave trials in benchmark script
This should be more of a fair A/B test so the timings aren't affected by having different load on your system when testing the two alternatives.
2016-05-14 12:04:25 -07:00
Ben Alpert
cab835d3a0 Make benchmark script work in React 15 2016-05-14 12:03:51 -07:00
Paul O’Shannessy
fc1cfb6225 Make React.__spread warn 2016-04-07 17:30:23 -07:00
Paul O’Shannessy
1573baaee8 Use Object.assign directly and inject object-assign at compile 2016-04-04 09:53:25 -07:00
Sebastian McKenzie
1365498b81 Update to Babel 6 2016-02-26 16:49:32 -08:00
cpojer
383e2f938d Update to jest-cli 0.9. 2016-02-17 13:01:14 +09:00
Paul O’Shannessy
7c52b802b4 Clean up ununsed devDeps
Also removed object-assign. We only support building with node v4+ which has Object.assign.
2016-01-22 10:17:30 -08:00
Rick Beerendonk
bef45b0b1a Year-agnostic copyright message, like React Native uses, to prevent the need for yearly changes. 2015-12-29 20:20:32 +01:00
Ben Alpert
3997164418 Merge pull request #5550 from spicyj/cc-speed
Make createClass 10-15% faster on complex specs
2015-12-14 14:45:44 -08:00
Justas Brazauskas
0886273438 Fix few typos in React docs and comments 2015-12-13 16:39:07 +02:00
Ben Alpert
ba0792e72b Add createClass stress test
Running this is left as an exercise for the reader, since my measure.py isn't designed for this at present. But something like this might work:

```diff
diff --git a/scripts/bench/measure.py b/scripts/bench/measure.py
index 4cedf47..627ec97 100755
--- a/scripts/bench/measure.py
+++ b/scripts/bench/measure.py
@@ -79,15 +79,12 @@ def _measure_ssr_ms(engine, react_path, bench_name, bench_path, measure_warm):
             if (typeof React !== 'object') throw new Error('React not laoded');
             report('factory_ms', END - START);

-            globalEval(readFile(ENV.bench_path));
-            if (typeof Benchmark !== 'function') {
-              throw new Error('benchmark not loaded');
-            }
+            globalEval("bm = (function(){" + readFile("bench-createclass-madman.js") + "})");
+            bm();
             var START = now();
-            var html = React.renderToString(React.createElement(Benchmark));
-            html.charCodeAt(0);  // flatten ropes
+            bm();
             var END = now();
-            report('ssr_' + ENV.bench_name + '_cold_ms', END - START);
+            report('cc_' + ENV.bench_name + '_cold_ms', END - START);

             var warmup = ENV.measure_warm ? 80 : 0;
             var trials = ENV.measure_warm ? 40 : 0;
@@ -119,7 +116,7 @@ def _main():
         return 1
     react_path = sys.argv[1]

-    trials = 30
+    trials = 60
     sys.stderr.write("Measuring SSR for PE benchmark (%d trials)\n" % trials)
     for i in range(trials):
         for engine in [
@@ -132,7 +129,7 @@ def _main():
         sys.stderr.flush()
     sys.stderr.write("\n")

-    trials = 3
+    trials = 0#3
     sys.stderr.write("Measuring SSR for PE with warm JIT (%d slow trials)\n" % trials)
     for i in range(trials):
         for engine in [
```
2015-11-25 18:24:46 -08:00
Ben Alpert
844ca8b6b2 benchmarking: measure and analyze scripts
This uses wall-clock time (for now) so it's noisier than alternatives
(cachegrind, CPU perf-counters), but it's still valuable. In a future diff we
can make it use those.

`measure.py` outputs something that `analyze.py` can understand, but you can use `analyze.py` without `measure.py` too. The file format is simple:

```
$ cat measurements.txt
factory_ms_jsc_jit 13.580322265625
factory_ms_jsc_jit 13.659912109375
factory_ms_jsc_jit 13.67919921875
factory_ms_jsc_nojit 12.827880859375
factory_ms_jsc_nojit 13.105224609375
factory_ms_jsc_nojit 13.195068359375
factory_ms_node 40.4891400039196
factory_ms_node 40.6669420003891
factory_ms_node 43.52413299679756
ssr_pe_cold_ms_jsc_jit 43.06005859375
...
```

(The lines do not need to be sorted.)

Comparing 0.14.0 vs master:

```
$ ./measure.py react-0.14.0.min.js >014.txt
Measuring SSR for PE benchmark (30 trials)
..............................
Measuring SSR for PE with warm JIT (3 slow trials)
...
$ ./measure.py react.min.js >master.txt
Measuring SSR for PE benchmark (30 trials)
..............................
Measuring SSR for PE with warm JIT (3 slow trials)
...
$ ./analyze.py 014.txt master.txt
Comparing 014.txt (control) vs master.txt (test)
Significant differences marked by ***
% change from control to test, with 99% CIs:

* factory_ms_jsc_jit
    % change:  -0.56% [ -2.51%,  +1.39%]
    means: 14.037 (control), 13.9593 (test)
* factory_ms_jsc_nojit
    % change:  +1.23% [ -1.18%,  +3.64%]
    means: 13.2586 (control), 13.4223 (test)
* factory_ms_node
    % change:  +3.53% [ +0.29%,  +6.77%]  ***
    means: 42.0529 (control), 43.54 (test)
* ssr_pe_cold_ms_jsc_jit
    % change:  -6.84% [ -9.04%,  -4.65%]  ***
    means: 44.2444 (control), 41.2187 (test)
* ssr_pe_cold_ms_jsc_nojit
    % change: -11.81% [-14.66%,  -8.96%]  ***
    means: 52.9449 (control), 46.6953 (test)
* ssr_pe_cold_ms_node
    % change:  -2.70% [ -4.52%,  -0.88%]  ***
    means: 96.8909 (control), 94.2741 (test)
* ssr_pe_warm_ms_jsc_jit
    % change: -17.60% [-22.04%, -13.16%]  ***
    means: 13.763 (control), 11.3439 (test)
* ssr_pe_warm_ms_jsc_nojit
    % change: -20.65% [-22.62%, -18.68%]  ***
    means: 30.8829 (control), 24.5074 (test)
* ssr_pe_warm_ms_node
    % change:  -8.76% [-13.48%,  -4.03%]  ***
    means: 30.0193 (control), 27.3964 (test)
$
```
2015-11-18 16:26:01 -08:00
Ben Alpert
c525732147 Merge pull request #5023 from spicyj/jsc-perf
Add rudimentary jsc perf-counters runner
2015-10-30 17:06:30 -07:00
Paul O’Shannessy
b5d90f8c6b Merge pull request #5331 from tbroadley/typescript-test-windows
Fix for TypeScript test on Windows
2015-10-30 15:45:51 -07:00
Thomas Broadley
d77e161f99 use path library to normalize filepath 2015-10-31 07:38:47 +09:00