mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 14:16:12 +03:00
perf(es/transforms): Copy benchmarks from oxc
(#9602)
This commit is contained in:
parent
a9868820de
commit
24c3a0ce13
@ -154,6 +154,12 @@ name = "bugs"
|
||||
harness = false
|
||||
name = "minify"
|
||||
|
||||
|
||||
[[bench]]
|
||||
harness = false
|
||||
name = "oxc"
|
||||
|
||||
|
||||
[[bench]]
|
||||
harness = false
|
||||
name = "typescript"
|
||||
|
124
crates/swc/benches/assets/UserSettings.tsx
Normal file
124
crates/swc/benches/assets/UserSettings.tsx
Normal file
@ -0,0 +1,124 @@
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useEffect } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { z } from "zod";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { useTimePreferences } from "@calcom/features/bookings/lib";
|
||||
import { FULL_NAME_LENGTH_MAX_LIMIT } from "@calcom/lib/constants";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { telemetryEventTypes, useTelemetry } from "@calcom/lib/telemetry";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { Button, TimezoneSelect, Icon, Input } from "@calcom/ui";
|
||||
|
||||
import { UsernameAvailabilityField } from "@components/ui/UsernameAvailability";
|
||||
|
||||
interface IUserSettingsProps {
|
||||
nextStep: () => void;
|
||||
hideUsername?: boolean;
|
||||
}
|
||||
|
||||
const UserSettings = (props: IUserSettingsProps) => {
|
||||
const { nextStep } = props;
|
||||
const [user] = trpc.viewer.me.useSuspenseQuery();
|
||||
const { t } = useLocale();
|
||||
const { setTimezone: setSelectedTimeZone, timezone: selectedTimeZone } = useTimePreferences();
|
||||
const telemetry = useTelemetry();
|
||||
const userSettingsSchema = z.object({
|
||||
name: z
|
||||
.string()
|
||||
.min(1)
|
||||
.max(FULL_NAME_LENGTH_MAX_LIMIT, {
|
||||
message: t("max_limit_allowed_hint", { limit: FULL_NAME_LENGTH_MAX_LIMIT }),
|
||||
}),
|
||||
});
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
formState: { errors },
|
||||
} = useForm<z.infer<typeof userSettingsSchema>>({
|
||||
defaultValues: {
|
||||
name: user?.name || "",
|
||||
},
|
||||
reValidateMode: "onChange",
|
||||
resolver: zodResolver(userSettingsSchema),
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
telemetry.event(telemetryEventTypes.onboardingStarted);
|
||||
}, [telemetry]);
|
||||
|
||||
const utils = trpc.useUtils();
|
||||
const onSuccess = async () => {
|
||||
await utils.viewer.me.invalidate();
|
||||
nextStep();
|
||||
};
|
||||
const mutation = trpc.viewer.updateProfile.useMutation({
|
||||
onSuccess: onSuccess,
|
||||
});
|
||||
|
||||
const onSubmit = handleSubmit((data) => {
|
||||
mutation.mutate({
|
||||
name: data.name,
|
||||
timeZone: selectedTimeZone,
|
||||
});
|
||||
});
|
||||
|
||||
return (
|
||||
<form onSubmit={onSubmit}>
|
||||
<div className="space-y-6">
|
||||
{/* Username textfield: when not coming from signup */}
|
||||
{!props.hideUsername && <UsernameAvailabilityField />}
|
||||
|
||||
{/* Full name textfield */}
|
||||
<div className="w-full">
|
||||
<label htmlFor="name" className="text-default mb-2 block text-sm font-medium">
|
||||
{t("full_name")}
|
||||
</label>
|
||||
<Input
|
||||
{...register("name", {
|
||||
required: true,
|
||||
})}
|
||||
id="name"
|
||||
name="name"
|
||||
type="text"
|
||||
autoComplete="off"
|
||||
autoCorrect="off"
|
||||
/>
|
||||
{errors.name && (
|
||||
<p data-testid="required" className="py-2 text-xs text-red-500">
|
||||
{errors.name.message}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
{/* Timezone select field */}
|
||||
<div className="w-full">
|
||||
<label htmlFor="timeZone" className="text-default block text-sm font-medium">
|
||||
{t("timezone")}
|
||||
</label>
|
||||
|
||||
<TimezoneSelect
|
||||
id="timeZone"
|
||||
value={selectedTimeZone}
|
||||
onChange={({ value }) => setSelectedTimeZone(value)}
|
||||
className="mt-2 w-full rounded-md text-sm"
|
||||
/>
|
||||
|
||||
<p className="text-subtle mt-3 flex flex-row font-sans text-xs leading-tight">
|
||||
{t("current_time")} {dayjs().tz(selectedTimeZone).format("LT").toString().toLowerCase()}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<Button
|
||||
type="submit"
|
||||
className="mt-8 flex w-full flex-row justify-center"
|
||||
loading={mutation.isPending}
|
||||
disabled={mutation.isPending}>
|
||||
{t("next_step_text")}
|
||||
<Icon name="arrow-right" className="ml-2 h-4 w-4 self-center" aria-hidden="true" />
|
||||
</Button>
|
||||
</form>
|
||||
);
|
||||
};
|
||||
|
||||
export { UserSettings };
|
10777
crates/swc/benches/assets/parser.ts
Normal file
10777
crates/swc/benches/assets/parser.ts
Normal file
File diff suppressed because it is too large
Load Diff
2550
crates/swc/benches/assets/renderer.ts
Normal file
2550
crates/swc/benches/assets/renderer.ts
Normal file
File diff suppressed because it is too large
Load Diff
1117
crates/swc/benches/assets/table.tsx
Normal file
1117
crates/swc/benches/assets/table.tsx
Normal file
File diff suppressed because it is too large
Load Diff
96
crates/swc/benches/oxc.rs
Normal file
96
crates/swc/benches/oxc.rs
Normal file
@ -0,0 +1,96 @@
|
||||
extern crate swc_malloc;
|
||||
|
||||
use std::{fs, io::stderr, sync::Arc};
|
||||
|
||||
use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Bencher, Criterion};
|
||||
use swc::config::{Config, JscConfig, Options, TransformConfig};
|
||||
use swc_common::{errors::Handler, FileName, FilePathMapping, SourceMap, GLOBALS};
|
||||
use swc_compiler_base::SourceMapsConfig;
|
||||
use swc_ecma_ast::EsVersion;
|
||||
use swc_ecma_parser::{Syntax, TsSyntax};
|
||||
use swc_ecma_transforms::react::Runtime;
|
||||
|
||||
const FILES: &[&str] = &[
|
||||
"benches/assets/parser.ts",
|
||||
"benches/assets/renderer.ts",
|
||||
"benches/assets/table.tsx",
|
||||
"benches/assets/UserSettings.tsx",
|
||||
];
|
||||
|
||||
fn mk() -> swc::Compiler {
|
||||
let cm = Arc::new(SourceMap::new(FilePathMapping::empty()));
|
||||
|
||||
swc::Compiler::new(cm)
|
||||
}
|
||||
|
||||
fn bench_full(b: &mut Bencher, filename: &str, opts: &Options) {
|
||||
let c = mk();
|
||||
|
||||
let source = Arc::new(fs::read_to_string(filename).unwrap());
|
||||
|
||||
b.iter(|| {
|
||||
GLOBALS.set(&Default::default(), || {
|
||||
let handler = Handler::with_emitter_writer(Box::new(stderr()), Some(c.cm.clone()));
|
||||
|
||||
let fm = c.cm.new_source_file_from(
|
||||
FileName::Real(filename.to_string().into()).into(),
|
||||
black_box(source.clone()),
|
||||
);
|
||||
let _ = c.process_js_file(fm, &handler, opts).unwrap();
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
fn full_group(c: &mut Criterion) {
|
||||
for filename in FILES {
|
||||
for source_map in [true, false] {
|
||||
for react_dev in [true, false] {
|
||||
c.bench_function(
|
||||
&format!(
|
||||
"es/oxc/{}/sourceMap={}/reactDev={}",
|
||||
filename, source_map, react_dev
|
||||
),
|
||||
|b| {
|
||||
bench_full(
|
||||
b,
|
||||
filename,
|
||||
&Options {
|
||||
config: Config {
|
||||
jsc: JscConfig {
|
||||
target: Some(EsVersion::EsNext),
|
||||
syntax: Some(Syntax::Typescript(TsSyntax {
|
||||
tsx: filename.ends_with(".tsx"),
|
||||
..Default::default()
|
||||
})),
|
||||
transform: Some(TransformConfig {
|
||||
react: swc_ecma_transforms::react::Options {
|
||||
runtime: Some(Runtime::Automatic),
|
||||
development: Some(react_dev),
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
})
|
||||
.into(),
|
||||
..Default::default()
|
||||
},
|
||||
module: None,
|
||||
source_maps: if source_map {
|
||||
Some(SourceMapsConfig::Bool(true))
|
||||
} else {
|
||||
None
|
||||
},
|
||||
..Default::default()
|
||||
},
|
||||
swcrc: false,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
criterion_group!(benches, full_group);
|
||||
criterion_main!(benches);
|
@ -349,7 +349,7 @@ export interface TerserMangleOptions {
|
||||
reserved?: string[];
|
||||
}
|
||||
|
||||
export interface TerserManglePropertiesOptions {}
|
||||
export interface TerserManglePropertiesOptions { }
|
||||
|
||||
/**
|
||||
* Programmatic options.
|
||||
@ -671,6 +671,11 @@ export interface JscConfig {
|
||||
* Emit isolated dts files for each module.
|
||||
*/
|
||||
emitIsolatedDts?: boolean;
|
||||
|
||||
/**
|
||||
* Disable all lint rules.
|
||||
*/
|
||||
disableAllLints?: boolean;
|
||||
};
|
||||
|
||||
baseUrl?: string;
|
||||
@ -1154,7 +1159,7 @@ export interface Output {
|
||||
map?: string;
|
||||
}
|
||||
|
||||
export interface MatchPattern {}
|
||||
export interface MatchPattern { }
|
||||
|
||||
// -------------------------------
|
||||
// ---------- Ast nodes ----------
|
||||
@ -1386,7 +1391,7 @@ export type Expression =
|
||||
| OptionalChainingExpression
|
||||
| Invalid;
|
||||
|
||||
interface ExpressionBase extends Node, HasSpan {}
|
||||
interface ExpressionBase extends Node, HasSpan { }
|
||||
|
||||
export interface Identifier extends ExpressionBase {
|
||||
type: "Identifier";
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@swc/types",
|
||||
"packageManager": "yarn@4.0.2",
|
||||
"version": "0.1.12",
|
||||
"version": "0.1.13",
|
||||
"description": "Typings for the swc project.",
|
||||
"sideEffects": false,
|
||||
"scripts": {
|
||||
|
Loading…
Reference in New Issue
Block a user