There are a couple of things why your task not completes. The task that actual fails is the presentation of the graph. The ui.Chart.series does not have the option to set a bestEffort or maxPixels, thus we first have to use reduceRegion, and then print a chart of the resulting featurecollection.
First, note that you do not filter your collection by region. As such, your are trying to print a chart of thousands of images which are not in your region of interest. Thus we first filter the collection by date and region.
// define geometry
var geom = ee.Geometry.Point(-122.08384, 37.42503).buffer(50000);
// Load and filter the Sentinel-2 image collection.
var collection = ee.ImageCollection('COPERNICUS/S2_SR').select('B4', 'B8')
.filterDate('2019-05-01', '2019-09-30')
// Don't forget filtering the image by region
.filterBounds(geom)
Then note that we use the var collection in our following operations. We can get a feature for every mean B4 and B8 value by mapping over the image collection and applying reduceRegion on every image.
var meanVals = ee.FeatureCollection(collection.map(function(image){
var mean = image.reduceRegion({ reducer: 'mean',
geometry: geom,
scale: 10, // native scale of the bands
// bestEffort: true, // set bestEffort if run out of memory
// tileScale: 4, // set higher to increase speed
maxPixels: 1e15});
return ee.Feature(null, {meanB4: mean.get('B4'), meanB8: mean.get('B8')
}).set(image.toDictionary(image.propertyNames())); // copy the image properties
}));
If we set the maxPixels high enough, we are able to print the chart. Note that you can increase the scale or tileScale and enable the bestEffort arguments to increase speed of the calculations. Make sure you read the documentation about this to understand the differences. Also, you have the possibility to export the table (to assets or drive). See the link below.
print(ui.Chart.feature.byFeature(meanVals, 'system:time_start', ['meanB4','meanB8']));
Additional note: You will see that you get multiple values per day. That is due to the data distribution of the ESA. See for example here or here to first aggregate images taken at a similar day.
link code